【问题标题】:React Redux Get Current Path in Connected ComponentReact Redux 获取连接组件中的当前路径
【发布时间】:2020-11-30 07:33:23
【问题描述】:

我正在寻找一个隐藏在某些页面上的导航栏,并且需要在单击 <Link> react-router-dom 元素后更新路径。但是,Nav 组件是一个连通组件。

如何获取在站点导航期间也会更新的 URL 或路径?

【问题讨论】:

  • 使用withRouter包装组件,然后接受history作为prop,它是包含当前路径信息的对象

标签: reactjs react-redux react-router react-router-dom


【解决方案1】:

通过以下方式解决:

<Route path='' render={(props) => <Navbar path={props.location.pathname} />} />

然后在需要路径的导航栏中使用path

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2021-05-21
    • 1970-01-01
    相关资源
    最近更新 更多