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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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。

return;
}
}
Expand Down
Loading