question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating to a non-existent URL with no defaultLocale defined throws a TypeError

See original GitHub issue

I’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!

<div align="right">This question is available on Nuxt.js community (#c11)</div>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

5reactions
paulgvcommented, Jan 27, 2018

@bobcat1 just release v2.1.0 which comes with 2 new options noPrefixDefaultLocale and redirectRootToLocale : 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 😃

4reactions
paulgvcommented, Jan 26, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigating to a non-existent URL with no defaultLocale ...
I'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...
Read more >
defaultLocale is not keeping default lang in Next.js i18n
I'm trying to make my default language in Next.js i18n but always is getting "En" as default language called like fallback. And I...
Read more >
Change Log for Plesk Obsidian
Find out about changes, additions and updates to Plesk Obsidian on an iteration to iteration basis.
Read more >
Guide to working with authentication and single sign-on ...
Test your authentication tree by navigating to a URL similar to the ... If there is no default authentication locale, the node uses...
Read more >
Changelog - Sphinx documentation
#10498: gettext: TypeError is raised when sorting warning messages if a node has no line number. Patch by Adam Turner. #10493: HTML Theme:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found