这是我的情况:
我已经尝试过像这样使用Prompt:
<Prompt
when={this.getIsEditorDirty()}
message={location => `Are you sure you want to quit editing ?`}
/>
但是when
仅state
通过函数获取期望值,而不通过函数。因此,它的行为不正确。
由于只能通过一个函数(假设getIsEditorDirty()
)来知道编辑器是否脏,我似乎没有找到任何适当的方法来拦截任何类型的用户导航。
可能的解决方案或解决方法是什么?
我不知道在Router 5中是否仍然如此,但是在4中,true
如果编辑器是“干净的” ,我通过从作为“消息”道具传递的函数中返回来做到这一点。
getBlockMessage = () => {
return this.isChanged() ? LEAVE_MSG : true;
}
// ...
<Prompt message={this.getBlockMessage}/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句