Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switchLocalePath() doesn't work in plugins #480

Closed
LionelPaulus opened this issue Oct 9, 2019 · 2 comments · Fixed by #488
Closed

switchLocalePath() doesn't work in plugins #480

LionelPaulus opened this issue Oct 9, 2019 · 2 comments · Fixed by #488
Assignees

Comments

@LionelPaulus
Copy link

Version

v5.3.0

Reproduction link

https://codesandbox.io/embed/nuxt-i18n-switchlocalepath-bug-dbi7h

Steps to reproduce

Create a Nuxt plugin and try using switchLocalePath() in it.

What is expected ?

Function working: returning the locale path for the desired locale.

What is actually happening?

Function crashes with error:

Cannot destructure property params of 'undefined' or 'null'.
const { params, ...routeCopy } = this.$route

Additional comments?

I'm using nuxt 2.10.0 and nuxt-i18n 6.3.0

This bug report is available on Nuxt community (#c318)
@ghost ghost added the cmty:bug-report label Oct 9, 2019
@rchl rchl self-assigned this Oct 9, 2019
@LionelPaulus
Copy link
Author

Hey @rchl, any update on this? :)
If you have a workaround, it would be very helpful 🙏

@rchl
Copy link
Collaborator

rchl commented Oct 14, 2019

No workarounds. It needs a proper fix that requires some refactoring. Seems like this was never supported so it's not a trivial bug fix

@rchl rchl closed this as completed in #488 Oct 24, 2019
rchl added a commit that referenced this issue Oct 24, 2019
switchLocalePath didn't work from a Nuxt plugin or middleware
(from context.app) as it accessed properties on `this` that were not
accessible from there.

Fixed by creating a proxy interface that is consistent for both
Vue instances and Nuxt context so that switchLocalePath can access
same properties from it and get expected results.

Also:
  - Updated `differentDomains` tests to not use snapshot testing.
    Those actually were wrongly tested due to bug in test utils but
    failure wasn't caught in snapshot (it was supposed to have
    SEO disabled).

Resolves #480
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants