【发布时间】:2019-10-13 12:26:36
【问题描述】:
我有一个 react 应用程序使用 react-router 在页面之间路由。 问题是这样的: 我在以下路线的页面中:http://example.com/my-current-location/ 我想路由到http://example.com/my-next-location/
我尝试使用
this.props.history.push("/my-next-location")
但这需要我去http://example.com/my-current-location/my-next-location/ 这不是我需要的。
this.props.history.push("/my-next-location")
我需要的是一种导航到绝对路径的方法。 当然,
location.replace()
不会这样做,因为我不想刷新整页。 我怎样才能做到这一点?
【问题讨论】:
-
嗨。你有在你的主要 react-router 组件上声明的路径吗?如果您这样做,只需在您想要链接按钮的地方使用
<Link />。干杯!
标签: javascript reactjs react-router