How to handle query parameters in angular 2

后端 未结 12 818
灰色年华
灰色年华 2020-11-27 03:41

In my routable component I have

@RouteConfig {
  {path: \'/login\',   name: \'Login\', component: LoginComponent}
}  

But how

12条回答
  •  广开言路
    2020-11-27 04:23

    RouteParams are now deprecated , So here is how to do it in the new router.

    this.router.navigate(['/login'],{ queryParams: { token:'1234'}})
    

    And then in the login component you can take the parameter,

    constructor(private route: ActivatedRoute) {}
    ngOnInit() {
        // Capture the token  if available
        this.sessionId = this.route.queryParams['token']
    
    }
    

    Here is the documentation

提交回复
热议问题