Navigating to a non-existent URL with no defaultLocale defined throws a TypeError
See original GitHub issueI’m trying to create a website with all content shown at example.com/en
(or /fr, /es, /it etc.) So basically when you go to example.com, I want to redirect to /en /fr /es… based on certain parameters, such as cookies and the browser locale.
While trying to figure out a way to do this, the first step was skipping defining a defaultLocale
. That way, all my languages are under their respective /locale/ url (it is also necessary to include the trailing slash, otherwise you get the error shown below).
However, when navigating to a non-existent URL without a defaultLocale
, you get:
{ TypeError: Cannot set property 'error' of undefined
at Object.error (.nuxt/index.js:91:0)
at module.exports.__webpack_exports__.a (.nuxt/i18n.plugin.js:20:0)
at createApp (.nuxt/index.js:159:0)
at <anonymous> statusCode: 500, name: 'TypeError' }
Instead of the usual 404 not found
that you get with defaultLocale
defined.
So what I’m asking is more or less; is this expected behaviour? Are you supposed to always use a defaultLocale
? And do you have any suggestion as to how I can achieve what I am trying to achieve?
Ps. Thank you for a truly superb module, the localePath()
feature has helped me loads!
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top GitHub Comments
@bobcat1 just release v2.1.0 which comes with 2 new options
noPrefixDefaultLocale
andredirectRootToLocale
: https://github.com/paulgv/nuxt-i18n#options You can use these 2 options to force URL prefixes for languages as well as achieving simple redirections from/
to a given locale. Hope it helps a little, we still need to have an option for more complex redirections but it’s a start 😃@bobcat1 The TypeError issue has been fixed in Nuxt 1.2.0 https://github.com/nuxt/nuxt.js/releases/tag/v1.2.0
@andrade1379 That’s currently not possible since
switchLocalePath
is declared in a Vue mixin but it would be nice to have this option! I’ll think about it.