Subscribe to both route params and queryParams in Angular 2

前端 未结 7 1898
粉色の甜心
粉色の甜心 2020-12-14 00:45

I have set up the following routing system

export const MyRoutes: Routes = [
  {path: \'\', redirectTo         


        
7条回答
  •  [愿得一人]
    2020-12-14 01:12

    Use ActivatedRouteSnapshot from your ActivatedRoute

    ActivatedRouteSnapshot interface has params and queryParams property, and you could get the both value at the same time.

    constructor(private route: ActivatedRoute) {
        console.log(this.route.snapshot.params);
        console.log(this.route.snapshot.queryParams);
    }
    

    Edit : As OP stated, we only get the initial value of the parameters with this technique.

    Example Plunker

提交回复
热议问题