Last active
February 27, 2020 16:20
-
-
Save elawad/7db7205f4d7f6abab3e3afde763bbd24 to your computer and use it in GitHub Desktop.
RR4, Auth, Layouts, and SSR
This file contains 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
render() { | |
const { | |
isAuthenticated, | |
location: { pathname }, | |
route: { routes }, | |
} = this.props; | |
const branch = matchRoutes(routes, pathname); | |
const Layout = branch[0].route.emptyLayout ? EmptyLayout : DefaultLayout; | |
const screen = <Layout routes={routes} />; | |
if (isAuthenticated) { | |
return screen; | |
} | |
return <Redirect to="/login" />; | |
} |
This file contains 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
const routes = [ | |
{ component: Auth, | |
routes: [ | |
// Default Layout screens: | |
{ path: '/', | |
component: Home, | |
exact: true, | |
// loadData: () => Promise.resolve('Pre-fetch server data...'), | |
}, | |
{ path: '/about', | |
component: About | |
}, | |
// Empty Layout screens: | |
{ path: '/login', | |
component: Login, | |
emptyLayout: true, | |
}, | |
{ path: '/*', | |
component: FourOhFour, | |
emptyLayout: true, | |
}, | |
] | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment