angular - Redirigiendo a una URL con queryParams
Estoy creando una redirección en Angular 6
El redireccionamiento en sí es muy simple, funciona así
obtener la URL de destino de los parámetros:
this.returnUrl = this.route.snapshot.queryParams['route'] || '/';
Redirigir
if (this.returnUrl) {
this.router.navigate([this.returnUrl]);
} else {
this.router.navigate(['/']);
}
El problema que tengo es cuando la URL tiene parámetros en ella, por ejemplo:
URL de redirección es
'/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D'Como resultado, obtengo el error
Error: Cannot match any routes. URL Segment: 'survey/finish%3Fkey%3D7krmpqpC0P&mind%3DAkkoord&companyNumber%3D%255B%255BQ2%255D'¿Cómo puedo redirigir correctamente a la cadena dada?
Entonces http://localhost:4200/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D
Mi ruta se ve así
{
path: 'survey/finish',
component: CallbackComponent,
canActivate: [AuthGuard]
}
Respuesta #1
usar el método navigateByUrl:
if (this.returnUrl) {
this.router.navigateByUrl(this.returnUrl);
} else {
this.router.navigateByUrl('/');
}
