Skip to content

Commit

Permalink
Merge pull request justjavac#14 from JohannLai/master
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoAshin authored Mar 24, 2017
2 parents f7154ad + 278aa75 commit 7fa8263
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/react-router/docs/api/Prompt.md
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="确定吗?"/>
```

0 comments on commit 7fa8263

Please sign in to comment.