Open frederikheld opened 16 hours ago
Would you be able to provide a reproduction? 🙏
So what's missing from the code I already posted?
You have provided a code snippet but your issue could be caused by a variety of factors such as config and project structure. A minimal reproduction (stackblitz or repository) with steps on how to reproduce your issue would allow me to actually debug what's happening.
https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-za36nq?file=components%2FLangSwitcher.vue
I used your starter template. I copy & pasted the code from app.vue
into error.vue
and it already shows --> locale switcher links are broken
Both pages use the same LangSwitcher.vue
component provided by the starter template.
Hmm I see what you mean, what do you expect switchLocalePath
to return in this case?
The same as everywhere else. I use the same top bar for all pages, so I expect the language switcher to work everywhere the same. The error is just a different kind of content, but I don't see that page any different from the other pages. And I wonder why Nuxt does.
The language switcher would keep working if you add a catch all route/page, though going to a non existent route would not trigger an error anymore🤔 The core issue is not it being an error page but the trying to resolve a translated version of a non existent route. Would that fit your use case?
Ah, that makes sense.
TBH I'm not a fan of all the crude magic going on inside Nuxt. In Vue I would just have defined a catchall route in the router. But as Nuxt is stubborn about being different, I think that the nuxt-i18n
module should conform to that stubbornness.
At least the Nuxt error page takes care of sending the right http status code to the client. I suppose that I would have to create all that my self with the catchall approach? And how would I create such a catchall route in Nuxt?
Important context: I'm using Nuxt just for SSG. No Nitro, I'm just dumping the contents of .output/public
to static webhosting. I don't know if that would work with a catchall route but it works with error.vue
.
Environment
Build Modules: -
Reproduction
Describe the bug
According to nuxt docs, the
error.vue
page to generate a custom error page has to be located outside of thepages
directory in thesrc
directory side by side withApp.vue
.If I use the
switchLocalePath()
function on this page, it will always return a empty string instead of the actual locale path.I'm using the same piece of code in
src/error.vue
and insrc/pages/index.vue
, so I can say for sure that it should work.Additional context
No response
Logs
No response