首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用react-router添加深层链路

使用react-router添加深层链路
EN

Stack Overflow用户
提问于 2016-10-06 20:32:21
回答 1查看 315关注 0票数 0

使用以下路由配置-

代码语言:javascript
复制
<Router history={hashHistory}>
   <Route name="Home" path="/" component={BaseLayout}>
      <Route name="Gateways" path="/gateways" component={DashboardLayout}>
        <Route name="Login" path="/login" component={Login}/>                      
        <Route name=":id" path="/gateways/:id">
            <IndexRoute name="Dashboard"  component={ViewGateWay}/>                                 
            <Route name="Access Points" path="/accesspoints" component={AccessPoints}>                              
                <Route name=":id" path="/:id" component={ViewAccessPoint}/>
            </Route>
            <Route name="Devices" path="/devices" component={Devices}>                              
                <Route name=":id" path="/:id" component={ViewDevice}/>
            </Route>
        </Route>
        <IndexRoute component={Gateways} />
     </Route>                    
     <IndexRedirect to="Login" />
   </Route>
</Router>

在用于面包屑的路线中使用name。有一个侧边菜单,其中有链接到/gateways/:id/gateways/:id/devices/gateways/:id/accesspoints,此外,最后两个有链接到单独的设备和接入点使用Link作为/gateways/:id/devices/:id/gateways/:id/accesspoints/:id。当我在侧边菜单中给出链接时

代码语言:javascript
复制
<Link to="/gateways/${this.props.params.id}/accesspoints">Access Points</Link>

代码语言:javascript
复制
<Link to="/accesspoints">Access Points</Link>

我没有得到正确的页面。设备链接也是如此。我正在尝试实现下面的API与面包屑。

代码语言:javascript
复制
home/gateways/GW_ID1/dashboard
home/gateways/GW_ID1/accesspoints
home/gateways/GW_ID1/accesspoints/GW_AP1
home/gateways/GW_ID1/devices
home/gateways/GW_ID1/devices/GW_DV1

链接的正确方法是什么?不使用任何处理程序。

EN

回答 1

Stack Overflow用户

发布于 2016-10-07 16:54:13

集思广益之后,我提出了一个我想要实现的解决方案

代码语言:javascript
复制
    <Route name=":gid" path="/gateways/:gid">
        <Route name="Dashboard"  path="/gateways/:gid/dashboard"   component={ViewGateWay}/>                                    
        <Route name="Access Points" path="/gateways/:gid/accesspoints"  component={AccessPoints}>                               
            <Route name=":apid" path="/gateways/:gid/accesspoints/:apid" component={ViewAccessPoint}/>
        </Route>
        <Route name="Devices" path="/gateways/:gid/devices"  component={Devices}>                               
               <Route name=":did" path="/gateways/:gid/devices/:did" component={ViewDevice}/>
        </Route>
</Route>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39896114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档