Angular2 router keep query string

前端 未结 9 1736
栀梦
栀梦 2020-11-29 01:52

I wrote an Angular2 (v2.0.1) application that makes use of the router. The website is loaded with several query string parameters, so the full URL initially looks like this:

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 02:13

    Günter Zöchbauer's answer should work properly but, for some reason, it is not working for me at all. What did end up working was passing the queryParams directly instead of 'preserving' them.

    This is what my guard looks like:

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        (...)
        this.router.navigate(['login'], { queryParams: route.queryParams });
    }
    

提交回复
热议问题