Closed
Description
Consider this setup:
routes: [{
path: 'profile/:profileId',
component: ProfileComponent,
beforeEnter (to, from, next) {
//Fired the first time the profile route is matched
},
}]
The first time the route is matched, the beforeEnter
callback is executed which allows me to implement any guards I want. This is however not the case if I navigate from profile/user1
to profile/user2
. This works as intended and makes sense to me because the route isn't "entered" again. However, I see a valid use case for implementing a guard in this scenario and by reading closed issues, the only suggestion given before closing is to create a watcher for $route. This feels wrong for several reasons:
- There's no way to create a watcher for per-route beforeEnter configuration in the VueRouter constructor options.
- If implemented on the component, the component now knows about application route structure. This might be ok in many scenarios but I don't think it should be forced.
I suggest creating a beforeRouteUpdate
callback which works exactly the same way as beforeRouteEnter
, but only fires when a route param like :profileId
changes.