mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(nuxt): detect nested pages with /index
segments (#23404)
This commit is contained in:
parent
0844735187
commit
a6f845d1ec
@ -1,6 +1,6 @@
|
||||
import fs from 'node:fs'
|
||||
import { extname, normalize, relative, resolve } from 'pathe'
|
||||
import { encodePath } from 'ufo'
|
||||
import { encodePath, joinURL, withLeadingSlash } from 'ufo'
|
||||
import { logger, resolveFiles, useNuxt } from '@nuxt/kit'
|
||||
import { genArrayFromRaw, genDynamicImport, genImport, genSafeVariableName } from 'knitwork'
|
||||
import escapeRE from 'escape-string-regexp'
|
||||
@ -85,7 +85,7 @@ export async function generateRoutesFromFiles (files: ScannedFile[], shouldExtra
|
||||
route.name += (route.name && '/') + segmentName
|
||||
|
||||
// ex: parent.vue + parent/child.vue
|
||||
const path = route.path + getRoutePath(tokens).replace(/\/index$/, '/')
|
||||
const path = withLeadingSlash(joinURL(route.path, getRoutePath(tokens).replace(/\/index$/, '/')))
|
||||
const child = parent.find(parentRoute => parentRoute.name === route.name && parentRoute.path === path)
|
||||
|
||||
if (child && child.children) {
|
||||
|
@ -437,6 +437,28 @@ describe('pages:generateRoutesFromFiles', () => {
|
||||
path: '/wrapper-expose/other'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
description: 'should handle trailing slashes with index routes',
|
||||
files: [
|
||||
{ path: `${pagesDir}/index/index.vue` },
|
||||
{ path: `${pagesDir}/index/index/all.vue` }
|
||||
],
|
||||
output: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
children: [],
|
||||
file: `${pagesDir}/index/index/all.vue`,
|
||||
name: 'index-index-all',
|
||||
path: 'all'
|
||||
}
|
||||
],
|
||||
file: `${pagesDir}/index/index.vue`,
|
||||
name: 'index',
|
||||
path: '/'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user