https://codesandbox.io/s/2p2jxm6k5y
The application exposes three different routes :
router.js file.options property./about shows an error page (Cannot read property 'layout' of undefined)/contact, the page is shown properly.Navigating to /about or /contact should work by default, and not need the options property.
Navigating to /about shows an error page.
It does work properly by adding an empty options property. While not being ideal, it can be used to get around this issue.
Any reason you don't use a module or the nuxt.config.js to extend your routes, as it is suggested in the docs?
I may have missed this page from the documentation 馃槆
Do you mean calling something like this ?
export default function AboutModule () {
this.options.router.extendRoutes = (routes, ...args) => {
// Keep previously registered routes
this.options.router.extendRoutes(routes, ...args)
// Add new routes
routes.push({
path: '/about',
component: {
render: h => <h1>About</h1>
}
})
}
}
It will be even easier 鈽猴笍
The module container has a fn built-in for that 鈽猴笍
Docs: https://nuxtjs.org/api/internals-module-container#extendroutes-fn-
Example:
export default function AboutModule () {
this.extendRoutes((routes) => {
// Add new routes
routes.push({
path: '/about',
component: {
render: h => <h1>About</h1>
}
})
})
}
@manniL Whoa, I completely missed it when reading the documentation. Sorry about that. I let you decide if this issue should be closed since a solution is available.
Thanks !
Closing here as I think that this recommended way should cover the necessary cases 鈽猴笍
Most helpful comment
It will be even easier 鈽猴笍
The module container has a fn built-in for that 鈽猴笍
Docs: https://nuxtjs.org/api/internals-module-container#extendroutes-fn-
Example: