Skip to content

Instantly share code, notes, and snippets.

@muralimano28
Created February 14, 2017 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muralimano28/bc493f6a0dc12e79faed57c9209bafd4 to your computer and use it in GitHub Desktop.
Save muralimano28/bc493f6a0dc12e79faed57c9209bafd4 to your computer and use it in GitHub Desktop.
Routes file with dynamic routing
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