Skip to content

Commit

Permalink
fix: custom routes not analyzed in layer with custom srcDir (#3133)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Sep 25, 2024
1 parent 5caa83b commit b9e5296
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
18 changes: 14 additions & 4 deletions specs/custom_route_paths/module_configration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ await setup({
browser: true,
// overrides
nuxtConfig: {
extends: [fileURLToPath(new URL(`../fixtures/layers/layer-pages-custom-src-dir`, import.meta.url))],
i18n: {
defaultLocale: 'en',
customRoutes: 'config',
Expand Down Expand Up @@ -72,10 +73,10 @@ test('can not access to pick route path', async () => {
await page.locator('#lang-switcher-with-nuxt-link a').click()
await waitForURL(page, '/fr')

// disalbe href with <NuxtLink>
// disable href with <NuxtLink>
expect(await page.locator('#link-history').getAttribute('href')).toBe(null)

// disalbe direct url access
// disable direct url access
let res: Response | (Error & { status: () => number }) | null = null
try {
res = await page.goto(url('/fr/history'))
Expand All @@ -93,10 +94,10 @@ test('can not access to disable route path', async () => {
await page.locator('#lang-switcher-with-nuxt-link a').click()
await waitForURL(page, '/fr')

// disalbe href with <NuxtLink>
// disable href with <NuxtLink>
expect(await page.locator('#link-category').getAttribute('href')).toBe(null)

// disalbe direct url access
// disable direct url access
let res: Response | (Error & { status: () => number }) | null = null
try {
res = await page.goto(url('/fr/category/test'))
Expand All @@ -106,3 +107,12 @@ test('can not access to disable route path', async () => {
// 404
expect(res!.status()).toBe(404) // eslint-disable-line @typescript-eslint/no-non-null-assertion
})

test('#3076 - layer with custom `srcDir`', async () => {
const { page } = await renderPage('/custom-layer/custom')

await page.click(`#nuxt-locale-link-fr`)
await waitForURL(page, '/fr/custom-layer-french/custom')

expect(await page.url()).include('/fr/custom-layer-french/custom')
})
1 change: 1 addition & 0 deletions specs/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CustomModule from './module'
export default defineNuxtConfig({
modules: [CustomModule, '@nuxtjs/i18n'],

srcDir: '.',
i18n: {
restructureDir: false,
lazy: false,
Expand Down
13 changes: 13 additions & 0 deletions specs/fixtures/layers/layer-pages-custom-src-dir/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// https://nuxt.com/docs/guide/directory-structure/nuxt.config
export default defineNuxtConfig({
srcDir: 'src/app/',
i18n: {
customRoutes: 'config',
pages: {
'custom-layer/[slug]': {
en: '/custom-layer/[slug]',
fr: '/custom-layer-french/[slug]'
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts" setup>
const { locales } = useI18n()
const switchLocalePath = useSwitchLocalePath()
</script>

<template>
<div>
<h1>Hello from custom page!</h1>
<section id="lang-switcher-with-nuxt-link">
<strong>Using <code>NuxtLink</code></strong
>:
<NuxtLink
v-for="(locale, index) in locales"
:id="`nuxt-locale-link-${locale.code}`"
:key="index"
:exact="true"
:to="switchLocalePath(locale.code)"
>{{ locale.name }}</NuxtLink
>
</section>
</div>
</template>
2 changes: 1 addition & 1 deletion src/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const mergeLayerPages = (analyzer: (pathOverride: string) => void, nuxt:
if (layers.length === 1) return

for (const l of layers) {
const lPath = resolve(project.config.rootDir, l.config.rootDir, l.config.dir?.pages ?? 'pages')
const lPath = resolve(project.config.rootDir, l.config.srcDir, l.config.dir?.pages ?? 'pages')
debug('mergeLayerPages: path ->', lPath)
analyzer(lPath)
}
Expand Down

0 comments on commit b9e5296

Please sign in to comment.