ionic-team / ionic-team/ionic-framework

bug: redirect should trigger the beforeEnter of the target

Abierto
#23,135 1 comentario 0 reacciones 0 asignados Ver en GitHub
package: core type: bug
Lenguaje dominante
TypeScript
Estrellas
52.7k
Forks
13.3k
Merge medio
1 d 15 h
PR fusionados (30 d)
51

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.