Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(routing): make 404 lazy for server too
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent 62d1462 commit 6345592
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/common/routing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import {Loader, Dimmer, Header, Icon} from 'semantic-ui-react'
import _ from 'lodash'
import Dashboard from 'containers/Dashboard'
import Links from 'containers/Links'
import NotFound from 'containers/NotFound'

function asyncComponentCreator (url) {
return asyncComponent({
resolve: () => {
if (!process.env.BROWSER) {
// flow-disable-next-line
return require(`containers/${url}/index.jsx`).default
}
// flow-disable-next-line: The parameter passed to import() must be a literal string
return import(/* webpackChunkName:"[index].[request]" */ `containers/${url}/index.jsx`)
},
Expand Down Expand Up @@ -58,32 +61,26 @@ function routingFnCreator (useFor) {
name: 'Links'
},
{
component: NotFound,
component: asyncComponentCreator('NotFound'),
name: '404'
}
]

const fns = {
// Returns routing for React-Router
routing () {
return routes
.map(a =>
_.pick(a, ['path', 'strict', 'exact', 'component'])
)
return routes.map(a => _.pick(a, ['path', 'strict', 'exact', 'component', 'lazy']))
},
// Returns `name` + `path`. used in Header
meta () {
return routes
.map(a => _.pick(a, ['path', 'name', 'exact', 'strict']))
return routes.map(a => _.pick(a, ['path', 'name', 'exact', 'strict']))
}
}

return fns[useFor]
}

const createRequiredHistory = process.env.BROWSER
? createBrowserHistory
: createMemoryHistory
const createRequiredHistory = process.env.BROWSER ? createBrowserHistory : createMemoryHistory

export const getMetaRoutes = routingFnCreator('meta')
export const getRouterRoutes = routingFnCreator('routing')
Expand Down

0 comments on commit 6345592

Please sign in to comment.