ionic-team / ionic-team/ionic-framework

bug: redirect should trigger the beforeEnter of the target

Offen
#23,135 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
package: core type: bug
Vorherrschende Sprache
TypeScript
Sterne
52.7k
Forks
13.3k
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
51

Beschreibung

## Original issue (#22944)

I am creating a new issue as the original one has been locked without being resolved and without PR to resolve it.

The original issue is that the hooks of a redirect route not get executed before the redirection.

With:

```html

```

if you navigate to `/from` you will navigate to `/to` without the `beforeEnter` of that route being executed. That is a problem when the `beforeEnter` hook handle authentication or lazy loading of the component.

## Additional issue

The same problem exists with a `beforeEnter`/`beforeLeave` hook returning a redirection. In that case the `beforeEnter` hook of the target route is not executed.

## Root cause / solution

The [documentation](https://ionicframework.com/docs/api/route-redirect#multiple-route-redirects) mentions:

> A route redirect will never call another redirect after its own redirect, since this could lead to infinite loops.

I think this limitation should be dropped. It is quite common to have a catch all route redirecting to the home page and you might want to log in users or lazy load a component in the `beforeEnter` hook of the page.

There are multiple strategies to prevent infinite loop:
- limiting the number of redirections,
- keeping track of the visited routes and generate an error when a loop is detected.

Both can be implemented (even if the former will also cover the later) to print better error message.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.