forked from justjavac/react-router-v4-CN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request justjavac#14 from JohannLai/master
- Loading branch information
Showing
1 changed file
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,44 @@ | ||
# <Prompt> | ||
|
||
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>`。 | ||
|
||
```js | ||
import { Prompt } from 'react-router' | ||
|
||
<Prompt | ||
when={formIsHalfFilledOut} | ||
message="Are you sure you want to leave?" | ||
message="你确定要离开吗?" | ||
/> | ||
``` | ||
|
||
## message: string | ||
|
||
The message to prompt the user with when they try to navigate away. | ||
|
||
当用户尝试导航离开时,提示用户的消息。 | ||
|
||
```js | ||
<Prompt message="Are you sure you want to leave?"/> | ||
<Prompt message="你确定要离开吗?"/> | ||
``` | ||
|
||
## 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 or `true` to allow the transition. | ||
会与用户试图前往下一个`地址`(location) 和 `action` 一起被调用。 | ||
|
||
函返回一个字符串用作向用户提示,或者返回`true`用作允许过渡。 | ||
|
||
```js | ||
<Prompt message={location => ( | ||
`Are you sure you want to go to ${location.pathname}?` | ||
`你确定你要前往 ${location.pathname} 吗?` | ||
)}/> | ||
``` | ||
|
||
## 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. | ||
你可以随时渲染`<Prompt>`,而不是有条件地在警戒后面渲染它。 | ||
|
||
- 当`when={true}` 时,禁止导航 | ||
- 当`when={false}` 时,允许导航 | ||
|
||
```js | ||
<Prompt when={formIsHalfFilledOut} message="Are you sure?"/> | ||
<Prompt when={formIsHalfFilledOut} message="确定吗?"/> | ||
``` |