LocaleRoutePathSchema doesn't include some routes from RoutePathSchema
UfukUstali opened this issue · 5 comments
Describe the bug
Some routes that are in the RoutePathSchema are not included in the LocaleRoutePathSchema
export type RoutePathSchema =
"/"|"/de/catagories/:slug"|"/de/catagories"|"/de/"|"/de/me/"|"/de/search"|"/de/signin"|"/de/verify-request"|"/en/catagories/:slug"|"/en/catagories"|"/en/"|"/en/me/"|"/en/search"|"/en/signin"|"/en/verify-request"|"/fr/catagories/:slug"|"/fr/catagories"|"/fr/"|"/fr/me/"|"/fr/search"|"/fr/signin"|"/fr/verify-request"|"/me/"|"/signin"|"/tr/"|"/tr/catagories/:slug"|"/tr/catagories"|"/tr/me/"|"/tr/search"|"/tr/signin"|"/tr/verify-request"|"/verify-request"
;
export type LocaleRoutePathSchema =
"/"|"/me/"|"/signin"|"/verify-request"
As can be seen in the above example the "/catagories" and "/catagories/:slug" are not included in the LocaleRoutePathSchema.
It is only the type that is broken when I pass "/catagories" to somewhere where the LocalRoutePathSchema is the type it functions without an issue.
On a completely unrelated matter could you guys take a look at my other issue on the nuxt i18n repo. It's about the newly introduced NuxtLinkLocale component.
Expected behavior
LocaleRoutePathSchema should be identical to RoutePathSchema other than the fact that it should not include all of the locale variations.
Environnement infos
- Operating System: Windows_NT
- Node Version: v18.16.0
- Nuxt Version: 3.7.4
- CLI Version: 3.9.1
- Nitro Version: 2.7.0
- Package Manager: pnpm@8.9.2
- Builder: -
- User Config: modules, ui, runtimeConfig, i18n, plausible, image, pwa, alias, devtools
- Runtime Modules: nuxt-typed-router@3.3.1, @nuxt/ui@2.9.0, @vueuse/nuxt@10.5.0, @nuxtjs/i18n@8.0.0-rc.5, @nuxt/image@1.0.0, @pinia/nuxt@0.4.11, @hebilicious/authjs-nuxt@0.3.5, @vite-pwa/nuxt@0.1.1, @nuxtjs/plausible@0.2.3, @vue-macros/nuxt@1.9.3
- Build Modules: -
Your pages
folder structure
pages
├── index
│ ├── catagories
│ │ ├── [slug].vue
│ │ └── index.vue
│ ├── index.vue
│ └── search.vue
├── index.vue
├── me
│ └── index.vue
├── me.vue
├── signin.vue
└── verify-request.vue
Your nuxt.config.ts
i18n: {
locales: [
{ code: "en", iso: "en-US", name: "English" },
{ code: "fr", iso: "fr-FR", name: "Français" },
{ code: "de", iso: "de-DE", name: "Deutsch" },
{ code: "tr", iso: "tr-TR", name: "Türkçe" },
],
defaultLocale: "en",
strategy: "prefix",
},
Hi! Thanks for the report i'll look into this
I did a little more digging and the situation seems to be different then what i described above.
export type RoutePathSchema =
"/"|"/de/catagories/:slug"|"/de/catagories"|"/de/"|"/de/me/"|"/de/search"|"/de/signin"|"/de/verify-request"|"/en/catagories/:slug"|"/en/catagories"|"/en/"|"/en/me/"|"/en/search"|"/en/signin"|"/en/verify-request"|"/fr/catagories/:slug"|"/fr/catagories"|"/fr/"|"/fr/me/"|"/fr/search"|"/fr/signin"|"/fr/verify-request"|"/me/"|"/signin"|"/tr/"|"/tr/catagories/:slug"|"/tr/catagories"|"/tr/me/"|"/tr/search"|"/tr/signin"|"/tr/verify-request"|"/verify-request"
;
The RoutePathSchema is also missing the "/catagories" and "/catagories/:slug" fields.
I was able to track it down until walkRoutes.ts file:
if (parent?.path !== "/") {
output.routesPaths.push({
name: route.name,
path: newPath,
isLocale: isLocaleRoute,
});
}
This if statement was preventing the generation of the routes directly under index "/" thereby all of the following were not generated ["/catagories/:slug", "/catagories", "/search"]
. The locale variations were not effected because their parent is technically "/en" or "/de" and so on. But when removed it causes the index route to be generated twice simply because i have a child route index under the root index route. e.g. ["/", "/", "/catagories/:slug", "/catagories", "/me/", "/search", "/signin", "/verify-request"]
pages
├── index <- from here
│ ├── catagories
│ │ ├── [slug].vue
│ │ └── index.vue
│ ├── index.vue <- the second index route was only generated after the modification
│ └── search.vue <- untill here was not generated unless it was locale route
├── index.vue < first index route was generated originally
├── me
│ └── index.vue
├── me.vue
├── signin.vue
└── verify-request.vue
This was the final solution i ended up that i think doesn't cause any issues
if (parent?.path !== "/" || newPath !== parent?.path) {
output.routesPaths.push({
name: route.name,
path: newPath,
isLocale: isLocaleRoute,
});
}
Do you want to make a PR or do you want me to udpate it? :) Thanks for the finding!
Just opened the PR