我有一个立即执行按钮,单击该按钮,检查3个条件(如果条件为真),然后重定向到另一条路线或组件
答案 0 :(得分:0)
类似的事情应该起作用
onClick={ ()=> {
if (condition1 && condition2 && condition3) {
this.setState({redirect : true}); // or setSomeVarible using useState
}
}
}
在渲染中(如果功能正常,则进行类似的检查作为回报)
if (this.state.redirect) {
return <Redirect to="/new-route" />
// or return <NewComponent />
// or window.location.href = 'https://whatever-url.com'
}