识别当前/活动的子路线

湿婆

我的路线如下所示:

<Route path="sites/:siteid" component={SiteContainer} >
        <Route path="restore/:version/:action" component={RestoreContainer} />
        <Route path="migrate/:version/:action" component={MigrateContainer} />
</Route>

如果我当前的网址是:

sites/1/restore/0/list

SiteContainerReact组件内部,我如何知道childRoutes当前正在提供哪个服务?如本例所示childRoutes[0]

湿婆

我终于想通了。Reactchildren通过以下方式为您提供了访问道具的权限

this.props.children

现在,当我访问URL时:

sites/1

正在访问主要路线,即loading SiteContainer因此,没有孩子null

在网址上时:

sites/1/restore/0/list

第一个子路由的组件(即RestoreContainer)变为children现在,我可以使用以下方式访问路线:

this.props.children.props.route

为了处理这两种情况,我在以下内容中进行了说明SiteContainer

childroute = this.props.children && this.props.children.props.route

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章