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

Commit

Permalink
fix: make all lazy routes
Browse files Browse the repository at this point in the history
fix: make all lazy routes
  • Loading branch information
Metnew committed Nov 4, 2017
1 parent c1e01f9 commit cce4088
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/common/routing/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@ import RouteAuth from 'components/addons/RouteAuth'
import {asyncComponent} from 'react-async-component'
import {Loader, Dimmer, Header, Icon} from 'semantic-ui-react'
import _ from 'lodash'
import Dashboard from 'containers/Dashboard'
import Links from 'containers/Links'
import Login from 'containers/Login'
import NotFound from 'containers/NotFound'
import type {RouteItem} from 'types'

function asyncComponentCreator (url) {
const importCreator = (url: string) => async () => {
const importCreator = (name: string) => {
// Read Webpack docs about code-splitting for more info.
if (process.env.BROWSER) {
// const resolve = import(/* webpackMode: "lazy", webpackChunkName: "[request].lazy" */ `containers/${url}/index.jsx`)
return import(/* webpackMode: "lazy", webpackChunkName: "[request].lazy" */ `containers/${url}/index.jsx`)
return import(/* webpackMode: "lazy", webpackChunkName: "[request].lazy" */ `containers/${name}/index.jsx`)
}
return import(/* webpackMode: "eager" */ `containers/${url}/index.jsx`)
return import(/* webpackMode: "eager" */ `containers/${name}/index.jsx`)
}

return asyncComponent({
resolve: importCreator(url),
resolve: () => importCreator(url),
LoadingComponent () {
return (
<Dimmer active>
Expand Down Expand Up @@ -67,7 +62,7 @@ function routingFnCreator (useFor: 'sidebar' | 'routing' | 'all' = 'all') {
name: 'Dashboard',
sidebarVisible: true,
tag: RouteAuth,
component: Dashboard
component: AsyncDashoard
},
{
path: '/links',
Expand All @@ -76,7 +71,7 @@ function routingFnCreator (useFor: 'sidebar' | 'routing' | 'all' = 'all') {
icon: 'bookmark',
sidebarVisible: true,
tag: RouteAuth,
component: Links
component: AsyncLinks
},
{
external: true,
Expand All @@ -90,13 +85,13 @@ function routingFnCreator (useFor: 'sidebar' | 'routing' | 'all' = 'all') {
name: 'Auth',
exact: true,
tag: Route,
component: Login
component: AsyncLogin
},
// Find the way to add/remove routes conditionally
{
name: '404',
tag: RouteAuth,
component: NotFound
component: AsyncNotFound
},
{
tag: Redirect,
Expand Down

0 comments on commit cce4088

Please sign in to comment.