Nic*_*las 2 redirect routes typescript angular
我正在创建一个角度为 6 的重定向
重定向本身非常简单,它的工作原理是这样的
从 params 获取目标网址:
this.returnUrl = this.route.snapshot.queryParams['route'] || '/';
Run Code Online (Sandbox Code Playgroud)
重定向
if (this.returnUrl) {
this.router.navigate([this.returnUrl]);
} else {
this.router.navigate(['/']);
}
Run Code Online (Sandbox Code Playgroud)
当 url 中有参数时我遇到的问题,例如:
重定向网址是
'/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D'
结果我得到了错误
Error: Cannot match any routes. URL Segment: 'survey/finish%3Fkey%3D7krmpqpC0P&mind%3DAkkoord&companyNumber%3D%255B%255BQ2%255D'
如何正确重定向到给定的字符串?
所以 http://localhost:4200/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D
我的路线看起来像这样
{
path: 'survey/finish',
component: CallbackComponent,
canActivate: [AuthGuard]
}
Run Code Online (Sandbox Code Playgroud)
Far*_*tab 10
使用navigateByUrl方法:
if (this.returnUrl) {
this.router.navigateByUrl(this.returnUrl);
} else {
this.router.navigateByUrl('/');
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3960 次 |
最近记录: |