标签: reactjs react-router
如果未保存文档,当我尝试转到另一个页面或端点时,我需要抛出警告
答案 0 :(得分:0)
有一种声明性的方法可以防止使用<Prompt>组件进行导航。
<Prompt>
<Prompt when={isBlocking} message={location => `Are you sure you want to go to ${location.pathname}` } />
isBlocking通常来自需要有条件呈现的组件状态。
isBlocking
您可以看到一个有效的示例here。