Skip to content

Instantly share code, notes, and snippets.

@NovoManu
Created December 7, 2020 13:01
Show Gist options
  • Save NovoManu/5ce1f2ff83924103153ec96ca3701efc to your computer and use it in GitHub Desktop.
Save NovoManu/5ce1f2ff83924103153ec96ca3701efc to your computer and use it in GitHub Desktop.
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