Skip to content

Suggestion for guard: beforeRouteUpdate #938

Closed
@wolthers

Description

@wolthers

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:

  1. There's no way to create a watcher for per-route beforeEnter configuration in the VueRouter constructor options.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions