我正在使用React和Ionic,在表单提交之后,我想以编程方式导航到下一条路线,
当我这样做的时候:
const { navigate } = useContext(NavContext);
// After Async call....
navigate("/", "forward", "pop").它起作用了。
当我在这里浏览ionic-react文档时: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>发布于 2021-01-29 20:12:51
有条件的navigate.In情况的示例代码任何问题都可以让我知道
import { useHistory } from 'react-router-dom';
const Form = () => {
const history = useHistory();
return(
<div>
if(condition){
history.push("/example")
}
</div>
)}https://stackoverflow.com/questions/65953951
复制相似问题