You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some subroutes in my app and want to watch for route changes in the parent. I use the beforeRouteUpdate-hook. I have a created-hook in the same Component. In a special state the app uses this.$router.push(...) in the created hook, but that throws an Error.
Vue warn]: Error in created hook:
(found in <App> at E:\Work\vue\src\App.vue)
warn @ vue.esm.js?65d7:558
handleError @ vue.esm.js?65d7:1443
...
TypeError: Cannot read property 'foo' of undefined
at beforeRouteUpdate (eval at <anonymous> (app.js:795), <anonymous>:7:21)
at boundRouteGuard (eval at <anonymous> (app.js:876), <anonymous>:1751:18)
I access this.foo in my beforeRouteUpdate-hook and it works fine but not if there is a redirect in the created hook.
I can have access to this in created(), but not in beforeRouteUpdate(), is this expected?
The text was updated successfully, but these errors were encountered:
cprass
changed the title
Created-hook route push together with beforeRouteUpdate
No this-access in beforeRouteUpdate() when changing route in created()
Mar 28, 2017
Thanks for reporting it. By triggering the route navigation in the created hook. The beforeRouteUpdate gets called before the router has access to the instance.
A workaround for the moment is using the mounted hook instead of the created one
Vue.js / vue-router versions
2.2.2 / 2.2.0
I have some subroutes in my app and want to watch for route changes in the parent. I use the
beforeRouteUpdate
-hook. I have acreated
-hook in the same Component. In a special state the app usesthis.$router.push(...)
in the created hook, but that throws an Error.I access
this.foo
in mybeforeRouteUpdate
-hook and it works fine but not if there is a redirect in the created hook.I can have access to
this
increated()
, but not inbeforeRouteUpdate()
, is this expected?Here is a repo that reproduces when you open the app and reload the page:
https://github.com/ChrisGitter/vue-router-beforeRouteUpdate/
The text was updated successfully, but these errors were encountered: