反应路由器this.props.location

反应路由器this.props.location,第1张

反应路由器this.props.location

您的

navbar
组件(如您在问题中所描述的)可能不是路由组件,对吗?通过
route component
我的意思是你在使用一个
react-router
被加载特定路由配置。

this.props.location
仅可通过此类访问
route component
,因此您需要将其传递给您
navbar

让我们举个例子:

您的路由器配置:

<Router>    <Route path="/" component={App}>    // ...</Router

路线部分

App

class App extends React.Component{  // ...  render() {    return <Navbar location={this.props.location}/>  }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5615003.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存