如何在按钮单击时重定向到另一个组件?

问题描述 投票:0回答:2

如何根据选定的下拉值重定向组件并使用反应路由器dom进行反应?

我尝试过使用Redirect标签,但我无法重定向到另一个组件

reactjs react-router-dom
2个回答
0
投票

您需要在onchange函数中使用props来转到另一个页面。

this.props.history.push('/my-other-components-url');

0
投票

来自react-router的链接组件可用于此:

<Link to="/other-components-url">
    <button>Click Me!</button>
</Link>

任何UI元素都可以嵌套在“链接”组件中,单击该组件时将重定向到指定的URL /组件。

欲了解更多详情,请访问:https://knowbody.github.io/react-router-docs/api/Link.html

© www.soinside.com 2019 - 2024. All rights reserved.