-
-
Save muralimano28/bc493f6a0dc12e79faed57c9209bafd4 to your computer and use it in GitHub Desktop.
Routes file with dynamic routing
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
import React from 'react'; | |
import { Router, browserHistory } from 'react-router/es6'; | |
import App from 'containers/App'; | |
function errorLoading(err) { | |
console.error('Dynamic page loading failed', err); | |
} | |
function loadRoute(cb) { | |
return (module) => cb(null, module.default); | |
} | |
const routes = { | |
component: App, | |
childRoutes: [ | |
{ | |
path: '/', | |
getComponent(location, cb) { | |
System.import('pages/Home') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
} | |
}, | |
{ | |
path: 'blog', | |
getComponent(location, cb) { | |
System.import('pages/Blog') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
} | |
}, | |
{ | |
path: 'about', | |
getComponent(location, cb) { | |
System.import('pages/About') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}, | |
childRoutes: [ | |
{ | |
path: 'company', | |
getComponent(location, cb) { | |
System.import('pages/About/Company') | |
.then(loadRoute(cb)) | |
.catch(errorLoading) | |
} | |
}, | |
{ | |
path: 'terms', | |
getComponent(location, cb) { | |
System.import('pages/About/Terms') | |
.then(loadRoute(cb)) | |
.catch(errorLoading) | |
} | |
} | |
] | |
}, | |
{ | |
path: 'new-page', | |
getComponent(location, cb) { | |
System.import('pages/New') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
} | |
} | |
] | |
}; | |
export default () => <Router history={browserHistory} routes={routes} />; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment