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.

Cannot access localePath in middleware

See original GitHub issue

I’m making a middleware which redirects users to some pages depending on the store informations. However, I’m lacking localePath to localise the path for the redirect. I expected it to be available as context.app.localePath, but it’s not.

More interestingly, it’s available at context.app.i18n.vm.localePath but the this context is not correct. localePath is somehow bound to a component which has neither $router or $i18n resulting in an error in i18n.routing.plugin.js

For now I’m running out of idea. I suspect that it might be a problem with nuxt lifecycle between plugins / middleware but it’s still obscure.

Versions: nuxt: 1.3 nuxt-i18n: 2.2.4

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

Issue Analytics

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

github_iconTop GitHub Comments

37reactions
unrcommented, May 31, 2018

Nevermind, actually found the answer to this looking at #25.

https://github.com/nuxt-community/nuxt-i18n/pull/25/files#diff-6aeb88ffa6a6d00ecc6e8f0487e8d069R66

You can access localePath via app.localePath, not app.i18n.localePath, like we’re all expecting.

0reactions
paulgvcommented, Apr 25, 2019

@mrleblanc101 done! Feel free to open PRs to help improve the doc, it can be done right in GitHub by clicking the Edit this page on GitHub link at the bottom of each documentation page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxt-modules/i18n - Cannot access localePath in middleware
I'm making a middleware which redirects users to some pages depending on the store informations. However, I'm lacking localePath to localise ...
Read more >
Nuxt: i18n.localePath access in middleware - vue.js
Yes, for some reason localePath does not work in middleware. You probably should detect current locale manualy. let locale = app.i18n.locale ...
Read more >
[Solved]-Nuxt: i18n.localePath access in middleware-nuxt.js
Yes, for some reason localePath does not work in middleware. You probably should detect current locale manualy. let locale = app.i18n.locale === app.i18n....
Read more >
Language Aware Nuxt.js Routing - Abdelrahman Awad
First we need access to the current locale, we can do that by accessing the parent from the render function context (2nd argument),...
Read more >
A Guide to Localizing with Nuxt.js | Phrase
Open http://localhost:3000/ in your browser and you'll see the default application ... used when you cannot predict the number of items.
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