<Prompt>

当用户离开当前页的时候做出提示. 当你的应用处在特定状态, 此状态不希望用户离开时(例如填写表格到一半), 你应该使用<Prompt>

  1. import { Prompt } from 'react-router'
  2. <Prompt
  3. when={formIsHalfFilledOut}
  4. message="你确定要离开吗?"
  5. />

message: string

当用户尝试导航离开时,提示用户的消息。

  1. <Prompt message="你确定要离开吗?"/>

message: func

会与用户试图前往下一个地址(location) 和 action 一起被调用。

函返回一个字符串用作向用户提示,或者返回true用作允许过渡。

  1. <Prompt message={location => (
  2. `你确定你要前往 ${location.pathname} 吗?`
  3. )}/>

when: bool

你可以随时渲染<Prompt>,而不是有条件地在警戒后面渲染它。

  • when={true} 时,禁止导航
  • when={false} 时,允许导航
  1. <Prompt when={formIsHalfFilledOut} message="确定吗?"/>