递归生成嵌套路由(react-router 4.0以下)

function descRouter(routes) {
    return routes.map((route, i) => {
        if (route.routes) {
            return (
                
                    {descRouter(route.routes)}
                
            );
        } else {
            return ();
        }
    });
}

参数routes的结构如下:

[

{    path:'/',

   component: 'InterfaceList',

   routes: [ 

             {   path: 'aaa',


                  component:  'UserList',

              },

              {  path: 'bbb',


                  component:  'ProfileList',

              }

         ]

},
{


   path:'/ABCList',

   component: 'ABCList',

}

]

你可能感兴趣的:(react-router,4.0以下)