Redirecting to a url with queryParams
Redirecting to a url with queryParams
I'm creating a redirect in angular 6
The redirect itself is very simple it works like this
get destination url from params:
this.returnUrl = this.route.snapshot.queryParams['route'] || '/';
Redirect
if (this.returnUrl)
this.router.navigate([this.returnUrl]);
else
this.router.navigate(['/']);
The problem I have in when the url has parameters in it, for example:
Redirect URL is
'/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D'
'/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D'
As a result I get the error
Error: Cannot match any routes. URL Segment: 'survey/finish%3Fkey%3D7krmpqpC0P&mind%3DAkkoord&companyNumber%3D%255B%255BQ2%255D'
Error: Cannot match any routes. URL Segment: 'survey/finish%3Fkey%3D7krmpqpC0P&mind%3DAkkoord&companyNumber%3D%255B%255BQ2%255D'
How can I correctly redirect to the given string?
So http://localhost:4200/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D
http://localhost:4200/survey/finish?key=7krmpqpC0P&mind=Akkoord&companyNumber=%5B%5BQ2%5D
My route looks like thid
path: 'survey/finish',
component: CallbackComponent,
canActivate: [AuthGuard]
what do your routes look like?
– mast3rd3mon
Sep 4 '18 at 11:24
1 Answer
1
use navigateByUrl method:
if (this.returnUrl)
this.router.navigateByUrl(this.returnUrl);
else
this.router.navigateByUrl('/');
Thank you, this worked!
– Nicolas
Sep 4 '18 at 11:32
so mark it as the accepted answer!
– Fartab
Sep 4 '18 at 11:35
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I marked it as duplicate of this question because the issue is the same, and you might find a solution in the original question. If you think this doesn't fit your case, please let me know and explain why.
– trichetriche
Sep 4 '18 at 11:24