ionic-team / ionic-team/ionic-framework

bug: redirect should trigger the beforeEnter of the target

Aperta
#23,135 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
package: core type: bug
Lingua principale
TypeScript
Stelle
52.7k
Fork
13.3k
Merge medio
1g 15h
PR unite (30g)
51

Descrizione

## 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.