Skip to content

Commit

Permalink
fix(nuxt): detect nested pages with /index segments (#23404)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored and manniL committed Dec 11, 2023
1 parent 3e7693b commit d727a9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt/src/pages/utils.ts
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions packages/nuxt/test/pages.test.ts
Expand Up @@ -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: '/'
}
]
}
]

Expand Down

0 comments on commit d727a9e

Please sign in to comment.