impress/src/app/App.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-04-21 20:32:53 -07:00
import React from "react";
2020-09-15 05:35:01 -07:00
import {
BrowserRouter as Router,
Switch,
Route,
useLocation,
} from "react-router-dom";
2020-04-21 17:49:52 -07:00
2020-09-06 18:12:34 -07:00
import PageLayout from "./PageLayout";
import WardrobePageLayout from "./WardrobePage/WardrobePageLayout";
import { loadable } from "./util";
2020-05-18 00:20:48 -07:00
const HomePage = loadable(() => import("./HomePage"));
const UserItemListPage = loadable(() => import("./UserItemListPage"));
const WardrobePage = loadable(() => import("./WardrobePage"), {
fallback: <WardrobePageLayout />,
});
2020-04-25 23:55:39 -07:00
/**
* App is the entry point of our application. There's not a ton of exciting
* stuff happening here, mostly just setting up some globals and theming!
*
* To really dive into the code, try going down into a page component!
*/
2020-04-21 17:49:52 -07:00
function App() {
return (
2020-05-10 00:21:04 -07:00
<Router>
2020-09-15 05:35:01 -07:00
<ScrollToTop />
<Switch>
<Route path="/outfits/new">
<WardrobePage />
</Route>
<Route path="/outfits/:id">
<WardrobePage />
</Route>
<Route path="/user/:userId/lists/:ownsOrWants(owns|wants)/:listId">
<PageLayout>
<UserItemListPage />
</PageLayout>
</Route>
<Route path="/">
<PageLayout hideHomeLink>
<HomePage />
</PageLayout>
</Route>
</Switch>
2020-05-10 00:21:04 -07:00
</Router>
2020-04-21 17:49:52 -07:00
);
}
2020-09-15 05:35:01 -07:00
/**
* ScrollToTop scrolls to the top of the page when you navigate.
* Copied from https://reactrouter.com/web/guides/scroll-restoration/scroll-to-top.
*/
function ScrollToTop() {
const { pathname } = useLocation();
React.useEffect(() => window.scrollTo(0, 0), [pathname]);
return null;
}
2020-04-21 17:49:52 -07:00
export default App;