How to get all route params/data

前端 未结 6 558
执念已碎
执念已碎 2020-12-24 07:20

Given a route config

{
   path: \'/root/:rootId\',
   children: [{
       path: \'/child1/:child1Id\',
       children: [{
           path: \'/child2/:child2         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 07:56

    You need to iterate the route segments.

    Something like

    var params = [];
    var route = router.routerState.snapshot.root;
    do {
     params.push(route.params); 
     route = route.firstChild;
    } while(route);
    

    This gives you the list of params of each route segment, you then can read the param values from them that you want.

    Object.keys(params) might work to get all available param names from a param instance.

提交回复
热议问题