Created
December 7, 2020 13:01
-
-
Save NovoManu/5ce1f2ff83924103153ec96ca3701efc to your computer and use it in GitHub Desktop.
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
const defaultLayout = 'AppDefaultLayout' | |
export default pages | |
// Note: remove nested routes from pages | |
.filter(path => !path.some(childrenFilter)) | |
.map(async path => { | |
const { default: component } = await import(`../views/${path.join('/')}`) | |
const { layout, middlewares, name } = component | |
const route = `/${generateRoute([...path])}` | |
let children = [] | |
if (childrenByPath[route]) { | |
const promises = childrenByPath[route].map(async ({ path, route }) => { | |
const { default: childComponent } = | |
await import(`../views/${path.join('/')}`) | |
const { | |
layout: childLayout, | |
middlewares: childMiddleware, | |
name: childName | |
} = childComponent | |
return { | |
path: route, | |
name: childName, | |
component: childComponent, | |
meta: { | |
layout: childLayout || defaultLayout, | |
middlewares: childMiddleware || {} | |
} | |
} | |
}) | |
children = await Promise.all(promises) | |
} | |
return { | |
path: route, | |
name, | |
component, | |
meta: { | |
layout: layout || defaultLayout, | |
middlewares: middlewares || {} | |
}, | |
children | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment