以编程方式导航离子反应



我正在使用React和Ionic,在表单提交后,我想以编程方式导航到下一个路由,

当我这样做的时候:

const { navigate } = useContext(NavContext);
// After Async call....
navigate("/", "forward", "pop").

当我在这里浏览离子反应文档:https://ionicframework.com/docs/react/navigation#navigation时,我看到他们使用history以编程方式导航,它说note: history is a prop

我尝试了上面的语句,我得到:Property 'history' does not exist on type '{ children?: ReactNode; }'.

需要一个解释

App.tsx

<IonRouterOutlet>
<Route exact path="/" component={Dashboard} />
<Route path="/home" component={Home} exact={true} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
</IonRouterOutlet>

有条件导航的示例代码。如有任何问题请告诉我

import { useHistory } from 'react-router-dom';
const Form = () => {
const history = useHistory();
return(
<div>
if(condition){
history.push("/example")
}
</div>
)}

最新更新