Created
February 8, 2021 19:28
-
-
Save fidelman/8ebe35e0ab720294e68a9ddb91f9a4fb to your computer and use it in GitHub Desktop.
e-commerce.routing.example
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 useUserContext from './use-user-context' | |
| import { routerRegister } from './route-register' | |
| const App = () => { | |
| const userContext = useUserContext() | |
| return routeRegister.reduce((routes, route) => { | |
| if (route.predicate(userContext)) { | |
| routes.push(<Route path={route.path} exact={route.isExact} component={route.Component} key={route.id} />) | |
| } | |
| return routes | |
| }, []) | |
| } |
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 OrderScreen from 'some/where/order-screen.jsx' | |
| // maybe even a class | |
| export const routerRegister = [ | |
| { | |
| id: 'order-screen', | |
| Component: OrderScreen, | |
| path: '/order/:id', | |
| }, | |
| { | |
| id: 'products-screen', | |
| Component: ProducsScreen, | |
| path: 'products', | |
| isExact: true, | |
| predicate: ctx => ctx.isLoggedIn | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment