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

Commit

Permalink
fix(routing): move routes array to index.js
Browse files Browse the repository at this point in the history
fix(routing): move routes array to index.js
  • Loading branch information
Metnew committed Feb 18, 2018
1 parent 3f2cc04 commit 2f4b3ce
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 132 deletions.
94 changes: 92 additions & 2 deletions src/common/routing/index.jsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,92 @@
export history from './history'
export {getSidebarRoutes, getRouterRoutes, getRoutes} from './routes'
// @flow
import React from 'react'
import {createBrowserHistory, createMemoryHistory} from 'history'
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'

function asyncComponentCreator (url) {
return asyncComponent({
resolve: () => {
if (process.env.BROWSER) {
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`)
},
LoadingComponent () {
return (
<Dimmer active>
<Loader size="large" active>
Loading page...
</Loader>
</Dimmer>
)
},
ErrorComponent () {
return (
<Dimmer active>
<Header inverted as="h2" icon textAlign="center">
<Icon name="refresh" />
Refresh
<Header.Subheader>Got error while loading page.</Header.Subheader>
</Header>
</Dimmer>
)
},
autoResolveES2015Default: true,
env: process.env.BROWSER ? 'browser' : 'node',
serverMode: 'resolve'
})
}

function routingFnCreator (useFor) {
const [AsyncNotFound] = ['NotFound'].map(asyncComponentCreator)
// Dashboard and Links included in build
// NotFound(404) is lazy
const routes: any[] = [
{
path: '/',
exact: true,
component: Dashboard,
name: 'Dashboard'
},
{
path: '/links',
exact: true,
component: Links,
name: 'Links'
},
{
component: AsyncNotFound,
name: '404'
}
]

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

return fns[useFor]
}

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

export const getMetaRoutes = routingFnCreator('meta')
export const getRouterRoutes = routingFnCreator('routing')
export const history = createRequiredHistory()
130 changes: 0 additions & 130 deletions src/common/routing/routes.js

This file was deleted.

0 comments on commit 2f4b3ce

Please sign in to comment.