【发布时间】:2016-09-05 20:06:08
【问题描述】:
我的 React 应用中有一个页面,如果表单脏了,我想阻止用户离开。
在我的 react-routes 中,我正在使用这样的 onLeave 道具:
<Route path="dependent" component={DependentDetails} onLeave={checkForm}/>
而我的onLeave 是:
const checkForm = (nextState, replace, cb) => {
if (form.IsDirty) {
console.log('Leaving so soon?');
// I would like to stay on the same page somehow...
}
};
有没有办法阻止新路由触发并使用户保持在同一页面上?
【问题讨论】:
-
你用的是什么版本?
-
嗨@PhilVarg,我正在使用react-router@2.0.1 和react-router-redux@4.0.2
标签: reactjs react-router