应用程序将从身份验证提供程序接收重定向,但在url中没有散列。
我需要将params从http://host/?param1=123重定向到http://host/#/login?param1=123
如何配置路由?
{ path: '', redirectTo: '/login', pathMatch: 'full'},
{ path: 'login', component: LoginComponent },发布于 2019-06-14 14:01:36
必须在路线内进行吗?
Programmatically,我得到了如下的参照系供参考:
this.parameters = Object.assign({}, this.route.snapshot.parent.queryParams);现在您可以使用this.parameters重定向或在navigate queryParams参数中构建它们。
this.router.navigate(['/profile/3'], { queryParams: { position: pos, 'salary': 'expensive' } }); // add .then(() => {}) for promise用于重定向
this.router.navigate(['login'], { preserveQueryParams: true });模板HTML路由
<a [routerLink]="['/profile/3']" [queryParams]="{position:'boss', 'salary': 'expensive' }">如果你需要更多,告诉我,我会帮你的。
发布于 2019-06-14 14:04:12
使用当前的角路由配置redirectTo功能是不可能的。
您可以做的是编写一个[CanActivate]保护,将其放在空路由''上,并在保护内部将用户重定向到使用Router保存的查询参数或从Router返回UrlTree。
例如,在警卫内部,它可能看起来像(使用Router):
...
this.router.navigate(['login'], { preserveQueryParams: true });
...希望这能有所帮助。
https://stackoverflow.com/questions/56599514
复制相似问题