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

feat(Router): 路由跳转携带参数 #720

Merged
merged 1 commit into from
May 21, 2024

Conversation

SuxueCode
Copy link
Contributor

@SuxueCode SuxueCode commented May 20, 2024

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

当链接为/sale/custom/info?id=996这类带get参数退出再登录时,不能正确的带着参数进行跳转
应当将query合并进来,方可正常跳转

💡 需求背景和解决方案

带get参数时能正常跳转

📝 更新日志

  • feat(Router): 路由跳转携带参数

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@@ -39,7 +39,7 @@ router.beforeEach(async (to, from, next) => {
next({ path: to.fullPath, replace: true, query: to.query });
} else {
const redirect = decodeURIComponent((from.query.redirect || to.path) as string);
next(to.path === redirect ? { ...to, replace: true } : { path: redirect });
next(to.path === redirect ? { ...to, replace: true } : { path: redirect, query: to.query });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果我现在有一个地址

/login?to=https://xxx.xxx.com/login

这个时候会不会造成意外loop呢?
个人建议交给路由守卫处理而不是选择带参数重定向

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我试了下应该是不会有意外loop的,这里都是query下内的参数,除非原有在落地页做了特殊处理。
你们处理后的redirect本身也还是有参数的,只不过似乎router的机制,如果带参数的path和query不匹配,似乎会自动截断掉,例如/sale/custom/info?id=996他会重定向至/sale/custom/info,但是如果query带了,他似乎又是正常工作的....
这里还有一个考虑回调的情况,回调通常尾巴带有参数,这里如果参数不带过去的话,回调页处理起来似乎也比较麻烦一些?还要去判断一下redirectedFrom。

@timi137137 timi137137 changed the title fix(Route):带参数重定向时不能正常跳转的问题 feat(Router): 路由跳转携带参数 May 21, 2024
Copy link
Contributor

完成

@timi137137 timi137137 merged commit 6e0560f into Tencent:develop May 21, 2024
5 checks passed
@SuxueCode SuxueCode deleted the fix_router_bug branch May 21, 2024 02:45
@github-actions github-actions bot mentioned this pull request Nov 6, 2024
16 tasks
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 this pull request may close these issues.

2 participants