1
1
mirror of https://github.com/c8r/x0.git synced 2024-09-11 21:57:26 +03:00

Add module to routes

This commit is contained in:
Brent Jackson 2018-05-25 14:54:59 -04:00
parent 8785b252f4
commit fb872a888b
2 changed files with 4 additions and 2 deletions

View File

@ -19,6 +19,7 @@ const index = filename ? path.basename(filename, path.extname(filename)) : 'inde
const getComponents = req => req.keys().map(key => ({
key,
name: path.basename(key, path.extname(key)),
module: req(key),
Component: req(key).default || req(key)
}))
.filter(component => !/^(\.|_)/.test(component.name))
@ -96,7 +97,7 @@ const Router = IS_CLIENT ? BrowserRouter : StaticRouter
const App = withRouter(APP ? (require(APP).default || require(APP)) : DefaultApp)
export const getRoutes = async (components = initialComponents) => {
const routes = await components.map(async ({ key, name, Component }) => {
const routes = await components.map(async ({ key, name, module, Component }) => {
const exact = name === index
let pathname = exact ? '/' : '/' + name
const props = Component.getInitialProps
@ -108,6 +109,7 @@ export const getRoutes = async (components = initialComponents) => {
name,
path: pathname,
exact,
module,
Component,
props
}

View File

@ -17,7 +17,7 @@
"author": "Brent Jackson",
"license": "MIT",
"dependencies": {
"@compositor/jsx-loader": "^1.0.0-2",
"@compositor/jsx-loader": "^1.0.0-3",
"@compositor/log": "^1.0.0-0",
"@mdx-js/loader": "^0.9.0",
"@mdx-js/mdx": "^0.9.0",