React-Router:如何检索当前路由的父级?

时间:2015-12-18 08:02:29

标签: reactjs react-router

如何检索当前路线的父母?我需要它才能够导航" up"在我的应用程序中。

1 个答案:

答案 0 :(得分:1)

在子组件的渲染中 -

var currentPath = this.props.location.pathname,
parentPath = currentPath.substring(0, currentPath.lastIndexOf("/"));
return (<Link to={parentPath}>Up</Link>...);