Vlad N
Vlad N

Reputation: 651

Angular return URL is wrong

In my Angular 5 Application I am doing something like this at

this.returnUrl = this.route.snapshot.queryParams['returnUrl']

I am using this when a user accesses a route but it's not logged in. He is redirected to the login page and after login he should be going back to this return url.

The problem is that http://localhost:4200/schedule?selectedDate=2018-01-29 when accessing this route, the return url becomes:

http://localhost:4200/login?returnUrl=%2Fschedule%3FselectedDate%3D2018-01-29 and after the successful login, the application tries to go to the http://localhost:4200/%2Fschedule%3FselectedDate%3D2018-01-29 URL but that throws a 404 error since it does not recognize the path.

Any idea how can I stop Angular changing my url to this format ? I was assuming that it would pick up the correct URL.

Upvotes: 0

Views: 2948

Answers (3)

Vlad N
Vlad N

Reputation: 651

I managed to somehow fix this by instead of using

this.router.navigate(this.returnUrl) 

I used

this.router.navigateByUrl(this.returnUrl);

Upvotes: 1

Supun Dharmarathne
Supun Dharmarathne

Reputation: 1148

Use this.

this.returnUrl = decodeURIComponent(this.route.snapshot.queryParams['returnUrl']);

Upvotes: 0

linto johny
linto johny

Reputation: 137

i think You can simply add the url like this <button class="btn btn-md btn-danger pull-right" routerLink="../../">cancel</button> or else call click event

Upvotes: 0

Related Questions