Last active
January 5, 2018 16:34
-
-
Save qalqi/ef4cbbc549631e64188266f0556be05f to your computer and use it in GitHub Desktop.
generator-react-firebase router in JSX format src/routes/index.js
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, {Component} from 'react' | |
import {IndexRoute, Route, IndexRedirect} from 'react-router' | |
import CoreLayout from 'layouts/CoreLayout' | |
import LevelOneLayout from 'layouts/LevelOneLayout/LevelOneLayout'; | |
import { | |
LIST_PATH, | |
ACCOUNT_PATH, | |
LOGIN_PATH, | |
SIGNUP_PATH, | |
HOME_PATH, | |
} from 'constants' | |
function errorLoading(err) { | |
console.error('Dynamic page loading failed', err); | |
} | |
function loadRoute(cb) { | |
return (module) => cb(null, module.default); | |
} | |
// Webpack 2 supports ES2015 `import()` by auto- | |
// chunking assets. Check out the following for more: | |
// https://webpack.js.org/guides/migrating/#code-splitting-with-es2015 | |
const importLogin = (nextState, cb) => { | |
import (/* webpackChunkName: "login" */ | |
'routes/Login/containers/LoginContainer') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importAccount = (nextState, cb) => { | |
import (/* webpackChunkName: "account" */ | |
'routes/Account/containers/AccountContainer') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importProjects = (nextState, cb) => { | |
import (/* webpackChunkName: "projects" */ | |
'routes/Projects/containers/ProjectsContainer') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importProject = (nextState, cb) => { | |
import (/* webpackChunkName: "project" */ | |
'routes/Projects/routes/Project/containers/ProjectContainer') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importNotFound = (nextState, cb) => { | |
import (/* webpackChunkName: "NotFound" */ | |
'routes/NotFound/NotFound') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importHome = (nextState, cb) => { | |
import (/* webpackChunkName: "home" */ | |
'routes/NewHome/components/Home') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
const importSignup = (nextState, cb) => { | |
import (/* webpackChunkName: "signup" */ | |
'routes/Signup/containers/SignupContainer') | |
.then(loadRoute(cb)) | |
.catch(errorLoading); | |
}; | |
/* Note: We are using JSX objects to build route definitions. */ | |
export const createRoutes = (store) => ( | |
<Route path="/" component={CoreLayout}> | |
<IndexRedirect to={HOME_PATH}/> | |
<Route path={LOGIN_PATH} getComponent={importLogin}></Route> | |
<Route path={ACCOUNT_PATH} getComponent={importAccount}></Route> | |
<Route path={SIGNUP_PATH} getComponent={importSignup}></Route> | |
<Route path={HOME_PATH} getComponent={importHome}></Route> | |
<Route path={LIST_PATH} getComponent={importProjects}> | |
<Route path=":projectname" getComponent={importProject}></Route> | |
</Route> | |
<Route path='*' exact={true} getComponent={importNotFound}/> | |
</Route> | |
) | |
export default createRoutes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment