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

SSR + Navigation Guards + Async Route Components Can Lead to Unintended Behavior #3331

Closed
j0Shi82 opened this issue Sep 25, 2020 · 1 comment

Comments

@j0Shi82
Copy link

j0Shi82 commented Sep 25, 2020

Version

3.4.4

Reproduction link

https://github.com/j0Shi82/vue-router-issue-3329

Steps to reproduce

  • pull repo
  • install nodejs
  • run npm install or yarn install
  • run npm run-script start or yarn run start
  • navigate to http://localhost:8085/one

What is expected?

Shows http://localhost:8085/two

What is actually happening?

Server Error 500


This is a follow-up to #3329 with a working reproduction and a little more information about what is actually causing the issue.

I'm not sure this is a bug or just an edge case that you have to work around yourself. It's caused by combining SSR, async route components, and redirects within navigation guards. I tried dodging async routes on the server and only using them on the client bundle (to still get the benefit of code-splitting), but that led to hydration errors.

Possible workarounds are switching to static route components, avoiding redirects within navigation guards, or using the router.push api instead of next. In our own application we went for the third choice on the server, but had to add additional logic to prevent hydration errors and handle the history mode correctly.

Either way it might make sense to go over the official SSR guide to better communicate this issue.

@j0Shi82 j0Shi82 changed the title SSR Navigation Guards Async Components Can Lead to Unintended Behavior SSR + Navigation Guards + Async Components Can Lead to Unintended Behavior Sep 25, 2020
@j0Shi82 j0Shi82 changed the title SSR + Navigation Guards + Async Components Can Lead to Unintended Behavior SSR + Navigation Guards + Async Route Components Can Lead to Unintended Behavior Sep 25, 2020
@posva
Copy link
Member

posva commented Sep 26, 2020

Thanks!

@posva posva closed this as completed in a1a290e Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants