mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 23:21:09 +00:00
fix(router): show default child if trailingSlash is false (#6594)
This commit is contained in:
parent
5272a48ea9
commit
c5465e65c8
@ -30,7 +30,7 @@ export const flatRoutes = function flatRoutes (router, fileName = '', routes = [
|
|||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanChildrenRoutes (routes, isChild = false, routeNameSplitter = '-') {
|
function cleanChildrenRoutes (routes, isChild = false, routeNameSplitter = '-', trailingSlash) {
|
||||||
let start = -1
|
let start = -1
|
||||||
const regExpIndex = new RegExp(`${routeNameSplitter}index$`)
|
const regExpIndex = new RegExp(`${routeNameSplitter}index$`)
|
||||||
const routesIndex = []
|
const routesIndex = []
|
||||||
@ -68,10 +68,15 @@ function cleanChildrenRoutes (routes, isChild = false, routeNameSplitter = '-')
|
|||||||
}
|
}
|
||||||
route.name = route.name.replace(regExpIndex, '')
|
route.name = route.name.replace(regExpIndex, '')
|
||||||
if (route.children) {
|
if (route.children) {
|
||||||
if (route.children.find(child => child.path === '')) {
|
const indexRoutePath = trailingSlash === false ? '/' : ''
|
||||||
|
const defaultChildRoute = route.children.find(child => child.path === indexRoutePath)
|
||||||
|
if (defaultChildRoute) {
|
||||||
|
if (trailingSlash === false) {
|
||||||
|
defaultChildRoute.name = route.name
|
||||||
|
}
|
||||||
delete route.name
|
delete route.name
|
||||||
}
|
}
|
||||||
route.children = cleanChildrenRoutes(route.children, true, routeNameSplitter)
|
route.children = cleanChildrenRoutes(route.children, true, routeNameSplitter, trailingSlash)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return routes
|
return routes
|
||||||
@ -188,7 +193,7 @@ export const createRoutes = function createRoutes ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
sortRoutes(routes)
|
sortRoutes(routes)
|
||||||
return cleanChildrenRoutes(routes, false, routeNameSplitter)
|
return cleanChildrenRoutes(routes, false, routeNameSplitter, trailingSlash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guard dir1 from dir2 which can be indiscriminately removed
|
// Guard dir1 from dir2 which can be indiscriminately removed
|
||||||
|
@ -260,7 +260,6 @@ Array [
|
|||||||
],
|
],
|
||||||
"chunkName": "pages/another_route/_id",
|
"chunkName": "pages/another_route/_id",
|
||||||
"component": "/some/nuxt/app/pages/another_route/_id.vue",
|
"component": "/some/nuxt/app/pages/another_route/_id.vue",
|
||||||
"name": "another_route-id",
|
|
||||||
"path": "/another_route/:id?",
|
"path": "/another_route/:id?",
|
||||||
"pathToRegexpOptions": Object {
|
"pathToRegexpOptions": Object {
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user