Skip to content

event.redirect() doesn't trigger the navigate event #280

@posva

Description

@posva

The current version of event.redirect() only allows to change (once) the final committed URL in an intercepted navigation. In SPA routers, navigation guards can redirect multiple times 1. Each redirection goes through navigation guards and can be redirected again. It's up to the developer to ensure no infinite loops (the router can help detect such cases during development).

If event.redirect() only allows to change the URL before it is committed, it would not allow routers to intercept redirections created by users and force them to only use router redirections (inside navigation guards) so that the router can create a consistent experience. This is the current situation with the History API, the router has to take over and this limits users to not use the History API directly. In practice this affects any plugin that interacts with History API because it needs to be specific to a framework router. It also affects micro frontends in general because they struggle to coordinate different framework routers (they have to pause them based on the page).

Another possible solution is to treat new redirections as a full new navigation2, but this would still mean to discourage users from using event.redirect().

Footnotes

  1. At least for Angular and Vue:

  2. https://github.com/WICG/navigation-api/issues/124#issuecomment-2684371423

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