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

this is undefined in beforeRouteLeave hook in some cases #1288

Closed
narwajea opened this issue Mar 29, 2017 · 9 comments
Closed

this is undefined in beforeRouteLeave hook in some cases #1288

narwajea opened this issue Mar 29, 2017 · 9 comments

Comments

@narwajea
Copy link

narwajea commented Mar 29, 2017

Vue.js / vue-router versions

2.1.10 / 2.1.3

Steps

  1. I detect the session is expired in a global HTTP interceptor: Vue.http.interceptors.push((request, next) => {...})

  2. I attempt to redirect the user so that he/she can authenticate: router.push({...})

  3. The beforeRouteLeave hook of a component is triggered

What is Expected?

this is defined

What is actually happening?

this is undefined

image

This seems to happen only locally, after my machine wakes up from sleep, while the Node.js server is still running, and after I make some changes to the code (with webpack hot reload enabled).

@fnlctrl
Copy link
Member

fnlctrl commented Mar 29, 2017

Hi, thanks for filling this issue. Please follow the Issue Reporting Guidelines and provide a live reproduction on jsfiddle, codepen etc. Thanks!

@narwajea
Copy link
Author

Unfortunately, I am not able to reproduce it on demand on my own environment..

@posva
Copy link
Member

posva commented Mar 29, 2017

Ok, if you ever manage to reproduce it, make sure to open a new issue 🙂

@posva posva closed this as completed Mar 29, 2017
@pastdevr
Copy link

pastdevr commented Apr 21, 2017

Hey, this issue can be reproduced.
For example, I have two routes /one, /two with same component. When I go from /one to /two this is defined in beforeRouteLeave hook. Then when I go from /two to some other route I have this is undefined.

@narwajea
Copy link
Author

I managed to reproduce it as well, but only on my own environment. I am not able to create a runnable reproduction link (JSFiddle / JSBin / CodePen) at this point.

@posva
Copy link
Member

posva commented Apr 21, 2017

If you manage to boil it down to the strict minimum on a repository, we can also look at that

@pastdevr
Copy link

pastdevr commented Apr 21, 2017

Look at this JSFiddle.
Steps to reproduce error:

  • Click /home (beforeRouteLeave is not invoked, ok)

  • Click /foo (this in beforeRouteLeave is defined, ok)

  • Click /bar (this in beforeRouteLeave is not defined, bad)

@pastdevr
Copy link

It looks like it fixed in 2.5.2 version of vue-router. Thanks

@nick-running
Copy link

@pastdevr thanks.the latest version certainly fixed that bug

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

5 participants