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

[bug] beforeEach hooks runs twice #966

Closed
lmk123 opened this issue Dec 1, 2016 · 2 comments
Closed

[bug] beforeEach hooks runs twice #966

lmk123 opened this issue Dec 1, 2016 · 2 comments
Labels

Comments

@lmk123
Copy link

lmk123 commented Dec 1, 2016

Vue.js version

2.1.3

vue-router version

2.1.0

Reproduction Link

https://jsfiddle.net/lmk123/qoj2sfb2/

What is Expected?

Alert should only shown once.

What is actually happening?

It shown twice.

@LinusBorg LinusBorg added the 2.x label Dec 1, 2016
@damianstasik
Copy link

damianstasik commented Dec 1, 2016

The first hook execution is done in VueRouter.init:

history.transitionTo(getHash())

The second execution is here:

this.transitionTo(getHash(), route => {

When the url doesn't contain the hash character, it will append #/ to the url and that will trigger the hashchange event which will run onHashChange and the second execution.

@lmk123
Copy link
Author

lmk123 commented Dec 2, 2016

@visualfanatic Thanks, just now I found this issue is duplicate (#725) and fixed in #735, sorry for my carelessness 😂

@lmk123 lmk123 closed this as completed Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants