0👍
✅
According to the doc :
The beforeRouteEnter guard does NOT have access to this, because the guard is called before the navigation is confirmed, thus the new entering component has not even been created yet.
So router
is still undefined since it is a plugin for the instance :
instead you can use afterEach
where the instance is created and the new route is navigated :
on your router
file :
router.afterEach((to,from)=>{
if (to == 'component') {
store.dispatch('getInvite')
}
})
// you don't have to use the if in case you want an API call after every navigation
NB : since afterEach
is not an “In-Component Guard” you need to import your store to router.js
file if you have the last one separated on its own folder
Source:stackexchange.com