URL Encoding breaking angular 2 navigation

前端 未结 2 1230
甜味超标
甜味超标 2021-01-23 04:32

I have a website developed in angular 2. When I provide optional parameters to it in chrome e.g.

https://aglplus-ui-demo.azurewebsites.net/home?error_code=10000&tra

相关标签:
2条回答
  • 2021-01-23 05:12

    The issue was happening when I was logged in to the system. There was a validation function which was redirecting using router.navigate(). Changing that to router.navigateByUrl() fixed the issue. However, I am not sure why that is the case. If someone can guide me regarding the same, I will be very obliged.

    0 讨论(0)
  • 2021-01-23 05:29

    If you have a path with a hash parameter and query parameters and you want to use 'navigate' method, you have to use the following form:

    router.navigate([path], {queryParams: queryParams, fragment: fragment, relativeTo: route});

    Or, as answered @krishanu-choudhury, you can use the

    router.navigateByUrl()

    method.

    0 讨论(0)
提交回复
热议问题