This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(routing): move routes array to index.js
fix(routing): move routes array to index.js
- Loading branch information
Showing
2 changed files
with
92 additions
and
132 deletions.
There are no files selected for viewing
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
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() |
This file was deleted.
Oops, something went wrong.