问题描述
我使用oauth身份验证登录用户.用户登录后,从URL获取.这样的网址: http://xxx/callback#access_token = xxx .然后重定向到其他页面.我使用 this.router.navigateByUrl 进行重定向,哈希标签已删除,但是当我单击其他链接时,哈希片段将再次显示.如何永久删除哈希令牌片段?
I use oauth authentication to login user. After the user has logged in, get taken from URL. URL like this: http://xxx/callback#access_token=xxx. then redirect to other page. I use this.router.navigateByUrl to redirect, the hash tag is removed but when I click other link,the hash fragment will show again. How can I remove the hash token fragment permanently?
示例:
使用后登录 //xxx/callback#access_token = xxx
after use login in //xxx/callback#access_token=xxx
重定向到 //xxx/home
redirect to //xxx/home
然后单击linkA,网址为 //xxx/linkA#access_token = xxx
then click linkA, the url is //xxx/linkA#access_token=xxx
预期的网址为 ///xxx/linkA
expected url is //xxx/linkA
推荐答案
我不知道您如何重定向,但我认为这是由您使用的方法引起的.
I don't know how you redirect but I assume it's caused by the method you use.
重置片段的一种方法是
<a routerLink="path" fragment="">
(尚未进行自我测试).
(not tested myself yet).
来自代码
let tree = this.router.navigate(['path'], {relativeTo: this.route, queryParams: ''});
另请参见 https://angular.io/api/router/Router#createurltree
这篇关于永久删除网址中的哈希片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!