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]





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






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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế