Created
January 4, 2020 23:18
-
-
Save ryanjyost/42e4d77a36237098555fe7c79e81824f to your computer and use it in GitHub Desktop.
Example 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import { Route, Switch, Redirect } from "react-router-dom"; | |
| import Login from "./Login"; | |
| const ROUTES = [ | |
| { path: "/", key: "ROOT", exact: true, component: Login }, | |
| { | |
| path: "/app", | |
| key: "APP", | |
| component: props => { | |
| if (!localStorage.getItem("user")) { | |
| alert("You need to log in to access app routes"); | |
| return <Redirect to={"/"} />; | |
| } | |
| return <RenderRoutes {...props} />; | |
| }, | |
| routes: [ | |
| { | |
| path: "/app", | |
| key: "APP_ROOT", | |
| exact: true, | |
| component: () => <h1>App Index</h1>, | |
| }, | |
| { | |
| path: "/app/page", | |
| key: "APP_PAGE", | |
| exact: true, | |
| component: () => <h1>App Page</h1>, | |
| }, | |
| ], | |
| }, | |
| ]; | |
| export default ROUTES; | |
| //... same below |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment