https://codesandbox.io/s/codesandbox-nuxt-9e9n1?fontsize=14
pages directoryrouter: { trailingSlash: false} to nuxt.config.jsIn the codesandbox, I created the following files
pages/
...
- users.vue
- users/
- index.vue
In https://9e9n1.sse.codesandbox.io/users, the contents of pages/users.vue & pages/users/index.vue are shown.
In https://9e9n1.sse.codesandbox.io/users/ (with trailingSlash), This page could not be found is shown
In https://9e9n1.sse.codesandbox.io/users, the contents of pages/users/index.vue is not shown. Only pages/users.vue is shown.
But in https://9e9n1.sse.codesandbox.io/users/ (with trailingSlash), the contents of both are shown.
Also, the following error appeared in console.
[vue-router] Named Route 'users' has a default child route. When navigating to this named route (:to="{name: 'users'"), the default child route will not be rendered. Remove the name from this route and use the name of the default child route for named links instead.
[vue-router] Duplicate named routes definition: { name: "users", path: "/users" }
The following is the summary of generated .nuxt/router.js
...
export const routerOptions = {
mode: 'history',
base: decodeURI('/'),
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
scrollBehavior,
routes: [{
path: "/users",
component: ...,
pathToRegexpOptions: {"strict":true},
name: "users",
children: [{
path: "",
component: ...,
pathToRegexpOptions: {"strict":true},
name: "users"
}]
},
...
],
fallback: false
}
...
In my opinion, to remove trailing slash,
name to parent of nested route. It's duplicated in childrenSo expected router.js may be
...
export const routerOptions = {
mode: 'history',
base: decodeURI('/'),
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
scrollBehavior,
routes: [{
path: "/users",
component: ...,
pathToRegexpOptions: {"strict":true},
children: [{
path: "/users",
component: ...,
pathToRegexpOptions: {"strict":true},
name: "users"
}]
},
...
],
fallback: false
}
...
Currently, my workaround is configuring nuxt.config.js as following
...
router: {
trailingSlash: false,
extendRoutes (routes) {
routes.forEach(r => {
if (!r.children) return
delete r.name
r.children.forEach(c => {
if (c.path !== '') return
c.path = r.path
})
})
}
}
...
Thanks for the report! I've implemented a naive bug fix in #6594 according to the error message. :relaxed:
Is this related #6783
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as pending will not be automatically marked as stale.
Most helpful comment
Thanks for the report! I've implemented a naive bug fix in #6594 according to the error message. :relaxed: