1 看下官方解释
弹窗出来之后点击确定返回true,点击取消返回false.
Used to prompt the user before navigating away from a page. When your application enters a state that should prevent the user from navigating away (like a form is half-filled out), render a <Prompt>
.
Prompt组件,当我们想往其他url地址跳转的时候,如果when的属性值是true,则会执行message
|
|
when: bool
Instead of conditionally rendering a <Prompt>
behind a guard, you can always render it but pass when={true}
or when={false}
to prevent or allow navigation accordingly.
粗暴点来理解,
- 如果我们传入一个true,那么则会渲染Prompt,接着执行message函数,渲染该函数的返回值,会询问用户是否确定跳转.
- 如果传入一个false,那么就会直接跳转到我们点击的url链接,
message: string
The message to prompt the user with when they try to navigate away.
|
|
message: func
Will be called with the next location
and action
the user is attempting to navigate to.
- Return a string to show a prompt to the user 此时如果用户点击确定,则返回true,允许跳转
- or
true
to allow the transition. - 传入message函数的变量是下一个location对象
|
|
|
|
2 官方demo改动理解
|
|
|
|
|
|
3 官方demo如下
|
|