ionic-team / ionic-team/ionic-framework

bug: redirect should trigger the beforeEnter of the target

オープン
#23,135 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
package: core type: bug
主要言語
TypeScript
スター
52.7k
フォーク
13.3k
平均マージ
1日 15時間
マージ済み PR(30日)
51

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。