-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Optional dynamic route not generated as expected #7571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In this case, the |
I tried to solve this problem myself and changed some code in function cleanChildrenRoutes(
routes: RouteConfig[],
isChild = false,
routeNameSplitter = '-',
): RouteConfig[] {
// let start = -1
const regExpIndex = new RegExp(`${routeNameSplitter}index$`)
const routesIndex: any[] = []
routes.forEach((route) => {
if (regExpIndex.test(route.name!) || route.name === 'index') {
// Save indexOf 'index' key in name
const res = route.name!.split(routeNameSplitter)
// const s = res.indexOf('index')
// start = start === -1 || s < start ? s : start
routesIndex.push(res)
}
})
routes.forEach((route) => {
route.path = isChild ? route.path.replace('/', '') : route.path
if (route.path.includes('?')) {
// const names = route.name!.split(routeNameSplitter)
const paths = route.path.split('/')
if (!isChild) {
paths.shift()
} // clean first / for parents
/******************* here is my code ****************** */
const dynamicIndex: number[] = []
paths.forEach((p, index) => {
if (p.startsWith(':') && p.endsWith('?')) dynamicIndex.push(index)
})
let n = routesIndex.length
while (dynamicIndex.length && n--) {
for (let i = dynamicIndex.length - 1; i >= 0; i--) {
if (routesIndex[n].includes(paths[dynamicIndex[i]].slice(1, -1))) {
paths[dynamicIndex[i]] = paths[dynamicIndex[i]].replace('?', '')
dynamicIndex.pop()
}
}
}
/** ************************************************** */
// routesIndex.forEach((r) => {
// const i = r.indexOf('index') - start // children names
// if (i < paths.length) {
// for (let a = 0; a <= i; a++) {
// if (a === i) {
// paths[a] = paths[a].replace('?', '')
// }
// if (a < i && names[a] !== r[a]) {
// break
// }
// }
// }
// })
route.path = (isChild ? '' : '/') + paths.join('/')
}
route.name = route.name!.replace(regExpIndex, '')
if (route.children) {
if (route.children.find((child) => child.path === '')) {
delete route.name
}
route.children = cleanChildrenRoutes(
route.children,
true,
routeNameSplitter,
)
}
})
return routes
} |
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
Should be fixed with v2.14.1 |
Version
v2.13.0
Reproduction link
https://codesandbox.io/s/naughty-framework-qb4jg?file=/pages/home/foo/edit/_id.vue
Steps to reproduce
see the repo link folder, same as:
What is expected ?
What is actually happening?
The text was updated successfully, but these errors were encountered: