如何访问当前组件中的最后路径? (React Router V6)
我想根据我们到达当前页面的位置,以不同的方式渲染UI。例如,如果我们来自“/mycollection”/apisearchResults',则项目详细信息页面应具有额外的“删除”按钮。在React Router V6中如何实现这一目标?
我知道我可以创建一个更高的组件,该组件封装了重用组件和额外功能。但是我想知道我是否可以没有事事。
谢谢!
I would like to render the UI differently depending on where we arrive at the current page. For example, an item detail page should have an extra 'delete' button if we come from '/mycollection' versus '/apiSearchResults'. How do I achieve this in react router v6?
I know I can create an Higher order component that encapsulates the reused component and the extra feature. But I am wondering if I can do without an HOC.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
< link>
组件传递状态,在这种情况下,请访问pathName:然后,您可以从
this.props.location.state
访问
< /代码>在下一个组件中prevather
You can pass down state using the
<Link>
component, in this case a pathname:You can then access
prevPath
fromthis.props.location.state
in the next component