ionic-team / ionic-team/ionic-framework

bug: redirect should trigger the beforeEnter of the target

未关闭
#23,135 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
package: core type: bug
主要语言
TypeScript
星标
52.7k
派生
13.3k
平均合并
1 天 15 小时
30 天内合并 PR
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.

贡献指南

打开贡献指南

调研方向

Start by tracing the route redirect handling and the beforeEnter/beforeLeave hooks described in the issue. Verify the behavior for /from redirecting to /to, including hook-returned redirects, and determine how redirect loops should be detected. Done means the target route's beforeEnter runs before navigation and loops produce a clear error rather than recurring indefinitely.

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
frontend
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。