0
在我有<Route>
代码的SideMenuNavigation组件中,我需要访问this.props.location.pathname
的值。不幸的是,我得到undefined
。在路由组件中访问this.props.location.pathname
class SideNavigation extends React.Component {
componentDidMount() {
console.log(this.props.location.pathname); // undefined
}
render() {
return(
<Router>
<Route exact path="/" component={Dashboard}/>
</Router>
)
}
}
/* */
在我的仪表板组件中,我可以成功访问this.props.location.pathname
。不幸的是,我不需要这个组件。我需要SideMenuNavigation
组件中的值。
我得到它与使用withRouter和无路径所以'出口默认与路由器(SideNavigation)'和<路由组件= {SideNavigation} />它已修复! :) –
devwannabe