how to pass RouteData via Router.navigate in angular2

后端 未结 2 740
执笔经年
执笔经年 2021-01-02 05:33

Is there an api in agnular2 that allows passing json objects instead of string values . E.g. In Router.navigate() I can pass route parameters

Ro         


        
2条回答
  •  囚心锁ツ
    2021-01-02 06:05

    Another Solution that works is using the params Property of RouterParams. This may not be the preferred way, but it works (as of Beta8).

    if you navigate with Router.navigate(['/myRoute',{someProperty:"SomeValue"}] you can access the param with:

    constructor(routeParams: RouteParams){
      let myPassedData: any = routeParams.params;
      console.log(myPassedData.someProperty); #Prints "SomeValue"
    }
    

提交回复
热议问题