在我的Angular 5应用程序中,我正在做类似的事情
this.returnUrl = this.route.snapshot.queryParams ['returnUrl']
当用户访问路由但未登录时,我正在使用此路由。他被重定向到登录页面,登录后,他应该返回该返回URL。
问题是http://localhost:4200/schedule?selectedDate=2018-01-29在访问此路由时,返回URL变为:
http://localhost:4200/login?returnUrl=%2Fschedule%3FselectedDate%3D2018-01-29,并在成功登录后,应用程序尝试转到http://localhost:4200/%2Fschedule%3FselectedDate%3D2018-01-29 URL,但由于无法识别路径而抛出404错误。
知道如何停止Angular将网址更改为这种格式吗?我以为它将选择正确的URL。
最佳答案
我设法以某种方式解决了这个问题,而不是使用
this.router.navigate(this.returnUrl)
我用了
this.router.navigateByUrl(this.returnUrl);