Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

路由redirect 时,查询参数被删除 #10606

Closed
cxb1021 opened this issue Feb 26, 2023 · 7 comments · Fixed by #12228
Closed

路由redirect 时,查询参数被删除 #10606

cxb1021 opened this issue Feb 26, 2023 · 7 comments · Fixed by #12228

Comments

@cxb1021
Copy link

cxb1021 commented Feb 26, 2023

What happens?

在路由的跳转过程中,如果是经过了redirect 匹配,查询参数会被删除。

How To Reproduce

路由配置

routes: [
    { path: "/one", component: "one" },
    { path: "/two", component: "two" },
    { path: "/", redirect: 'one' }
  ],

在路由/two下,通过history.push('/one?name=123') 跳转,跳转后的路由是/one?name=123。属于期望结果。

通过history.push('/?name=123') 跳转,经过redirect,跳转的路由是/one。查询参数name=123 被删除。不属于期望结果。

最小复现repo
https://github.com/cxb1021/umi_redirect_reproduce.git

期望结果:
无论路由通过哪种方式跳转,查询参数都应该保留。

  • Umi Version: 4.0.53
  • Node Version: 18.14.1
  • Platform: windows
@fz6m
Copy link
Member

fz6m commented Mar 4, 2023

这个目前是预期的,你可以写一个组件给 / ,然后在这里面重定向,带上你的参数。

@cxb1021
Copy link
Author

cxb1021 commented Mar 9, 2023

这个目前是预期的,你可以写一个组件给 / ,然后在这里面重定向,带上你的参数。

感谢回复和提供解决方案。但是我不认为这个预期的行为是合理的。主要的原因有:

1、删除参数的这个行为是有侵犯性的。因为参数是开发人员带上去的,而umi 本身是框架,这个角度来说,umi 应该只提供重定向的功能,但是该功能不经过同意删除参数,是侵犯了开发人员数据;

2、由于第一个原因,就导致umi 提供的路由重定向这个功能,对于开发人员来说不可靠,因为参数会被删除,不敢放心使用。也进一步减少了umi 路由重定向功能的价值;

3、这一条会主观一点,我之前的开发框架是angular,angular 中路由的每一个参数的控制权都在开发人员手里,并不会因为重定向而删除用户数据。这倒不是说angular 就一定对,但是从路由重定向这个功能而言,我认为angular 更加合理,umi 可以借鉴一下。

@showonne
Copy link

希望能保留 query && hash 的场景:
移动端页面,设备顶部的 padding 高度或是否默认开启 webview 导航栏等通过 query 控制时, 使用 redirect 会丢参数,导致显示问题

@ldc-37
Copy link

ldc-37 commented Dec 22, 2023

我也认为应当保留参数,跳转时清空参数是为了解决什么问题呢?

@yrnLhr
Copy link

yrnLhr commented Dec 25, 2023

同意,或者给一个参数用来开关也行呀,我不想创造没用的组件来干这个事

1 similar comment
@cdx111
Copy link

cdx111 commented Mar 25, 2024

同意,或者给一个参数用来开关也行呀,我不想创造没用的组件来干这个事

@Mustang-Galaxy
Copy link

这个目前是预期的,你可以写一个组件给 / ,然后在这里面重定向,带上你的参数。
这个是什么意思?没明白呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants