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

fix: initial redirect breaks reactivity in static mode #753

Merged
merged 2 commits into from Jun 5, 2020

Conversation

rchl
Copy link
Collaborator

@rchl rchl commented Jun 3, 2020

When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737

@codecov
Copy link

codecov bot commented Jun 3, 2020

Codecov Report

Merging #753 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #753   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files           3        3           
  Lines         129      129           
  Branches       35       35           
=======================================
  Hits          127      127           
  Misses          2        2           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 145f3b2...73e9a52. Read the comment docs.

When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
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 this pull request may close these issues.

Reactivity broken after redirecting from a plugin (nuxt generate)
1 participant