简体   繁体   English

角度返回URL错误

[英]Angular return URL is wrong

In my Angular 5 Application I am doing something like this at 在我的Angular 5应用程序中,我正在做类似的事情

this.returnUrl = this.route.snapshot.queryParams['returnUrl'] 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. 当用户访问路由但未登录时,我正在使用此路由。他被重定向到登录页面,登录后,他应该返回该返回URL。

The problem is that http://localhost:4200/schedule?selectedDate=2018-01-29 when accessing this route, the return url becomes: 问题是访问此路由时http:// localhost:4200 / schedule?selectedDate = 2018-01-29 ,返回URL变为:

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. http:// localhost:4200 / login?returnUrl =%2Fschedule%3FselectedDate%3D2018-01-29 ,成功登录后,应用程序尝试转到http:// localhost:4200 /%2Fschedule%3FselectedDate%3D2018- 01-29 URL,但由于无法识别路径而引发404错误。

Any idea how can I stop Angular changing my url to this format ? 知道如何停止Angular将网址更改为这种格式吗? I was assuming that it would pick up the correct URL. 我以为它将选择正确的URL。

I managed to somehow fix this by instead of using 我设法以某种方式解决了这个问题,而不是使用

this.router.navigate(this.returnUrl) 

I used 我用了

this.router.navigateByUrl(this.returnUrl);

我认为您可以像这样添加网址<button class="btn btn-md btn-danger pull-right" routerLink="../../">cancel</button> ,否则调用click事件

用这个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM