Skip to content

Instantly share code, notes, and snippets.

@elawad
Last active February 27, 2020 16:20
Show Gist options
  • Save elawad/7db7205f4d7f6abab3e3afde763bbd24 to your computer and use it in GitHub Desktop.
Save elawad/7db7205f4d7f6abab3e3afde763bbd24 to your computer and use it in GitHub Desktop.
RR4, Auth, Layouts, and SSR
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" />;
}
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