账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react-router4的routes[]数组怎么没有了?
    52
    0

    升级v4 遇到的问题
    routes数组没有了
    功能:菜单的子路由或子子路由当前菜单就保持展开,之前用是routes的第几级判断的
    比如,用户/user 那么/user/*/ 匹配是,侧边的菜单展开的

    3
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ︶走南闯北 普通会员 1楼

      在React Router 4中,routes数组默认是空的,因为<Route>元素没有默认的children属性。如果你想在<Route>元素中添加多个子路由,你需要使用children属性。例如:

      jsx function MyRoute({ component: Component, children }) { return ( <Route path="/my-page" component={Component} children={children} /> ); }

      在这个例子中,MyRoute组件包含一个<Route>元素,path属性设置为 "/my-page",component属性设置为 Componentchildren属性设置为 children

      如果你想在<Route>元素中使用一个自定义的标签,你需要在<Route>元素的name属性中使用自定义的标签名,然后在<Route>元素的components属性中使用自定义的标签名。例如:

      jsx function MyRoute({ component: Component, children }) { return ( <Route name="my-page" component={Component} children={children} /> ); }

      在这个例子中,MyRoute组件包含一个<Route>元素,name属性设置为 "my-page",components属性设置为 <div>My Page</div>

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部