Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a clear before handler that is called any time url navigation matches a route (not a route resolution / component). #3389

Copy link
Copy link
Closed
@sqcrh

Description

@sqcrh
Issue body actions

What problem does this feature solve?

It is a common need to create a route guard that checks if a user or resource is authorized or authenticated activating a route. This currently does not exist, and the existing per route beforeEnter handler really aligns with component activation not route activation. I think it makes more sense to include auth type guards in the url/routing module and not the component because the guard logic is shared among some large percentage of the routes and doesn't have relate specifically to component logic. And often you want this logic to apply to some routes not all routes. Currently to meet this need you have to:

  1. Watch $route. Not ideal, because you have to roll your own logic to match the guard to the route.
  2. Use the global beforeEach. Again, not ideal because you have to roll your own logic to apply guard to selected routes.
  3. Use beforeRouteUpdate and beforeRouteEnter in the component. This isn't ideal because the global auth guards should not be buried in a component and they don't use any component logic. The guard is related to the route.
  4. Reach for the beforeEnter handler, which only activates when the route resolution is changed but many people expect it to be called when the the route is matched

I think there is a need for this based the necessity of a call out in the documentation, a handful of issues in the repo, and questions on the forum. The current route paradigm makes sense and has parity when you are talking about a component (enter, update, leave). But when you talk about a route there is a parity mismatch. You would expect a route handler to be called an time the route url changes and a route is matched.

I see there is was a proposal to add a beforeUpdate, which I think was rightfully closed with an addition to the component.
#1577

There was also a proposal to deprecate beforeEnter, which I think actually makes sense because again beforeEnter is confusing, but without a replacement i understand why it was closed.
#2540

Some more relevant issues and questions:

What does the proposed API look like?

Deprecate confusing beforeEnter that really aligns with the component not the route and create a handler called before, beforeNavigate, or beforeMatch that is called before a route is matched and pushed onto the stack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.