Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 重定向到带有查询参数的url_Angular_Typescript_Redirect_Routes - Fatal编程技术网

Angular 重定向到带有查询参数的url

Angular 重定向到带有查询参数的url,angular,typescript,redirect,routes,Angular,Typescript,Redirect,Routes,我正在angular 6中创建重定向 重定向本身非常简单,它的工作原理如下 从参数获取目标url: this.returnUrl = this.route.snapshot.queryParams['route'] || '/'; 重定向 if (this.returnUrl) { this.router.navigate([this.returnUrl]); } else { this.router.navigate(['/']); } 当url中包含参数时,我遇到的问题,例如:

我正在angular 6中创建重定向

重定向本身非常简单,它的工作原理如下

从参数获取目标url

this.returnUrl = this.route.snapshot.queryParams['route'] || '/';
重定向

if (this.returnUrl) {
  this.router.navigate([this.returnUrl]);
} else {
  this.router.navigate(['/']);
}
当url中包含参数时,我遇到的问题,例如:

重定向URL

“/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D”

因此,我得到了错误

错误:无法匹配任何路由。URL段:“调查/完成%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]
  }

使用navigateByUrl方法:

if (this.returnUrl) {
  this.router.navigateByUrl(this.returnUrl);
} else {
  this.router.navigateByUrl('/');
}

我将其标记为,因为问题是相同的,您可能会在原始问题中找到解决方案。如果您认为这不适合您的情况,请让我知道并解释原因。您的路线是什么样子的?似乎有一个类似的解决方案对我有效。这是一个完美的解决方案-我想知道为什么这个线程被低估;)