Skip to content

Instantly share code, notes, and snippets.

@fidelman
Created February 8, 2021 19:28
Show Gist options
  • Select an option

  • Save fidelman/8ebe35e0ab720294e68a9ddb91f9a4fb to your computer and use it in GitHub Desktop.

Select an option

Save fidelman/8ebe35e0ab720294e68a9ddb91f9a4fb to your computer and use it in GitHub Desktop.
e-commerce.routing.example
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
}, [])
}
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