Skip to content

Commit

Permalink
Translated preventing-and-retrying-transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
towerhe committed Dec 5, 2013
1 parent a38b130 commit 5ad0da2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion data/guides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
url: "routing/asynchronous-routing"
- title: "加载中/错误子状态"
url: "routing/loading-and-error-substates"
- title: "Preventing and Retrying Transitions"
- title: "阻止和重试过渡"
url: "routing/preventing-and-retrying-transitions"
#- title: "Dynamic Segments"
#url: "routing/dynamic-segments"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ to immediately abort the transition by calling `transition.abort()`,
and if the transition object is stored, it can be re-attempted at a
later time by calling `transition.retry()`.

在一个路由过渡过程中,Ember路由器将一个过渡对象传递给过渡相关的路由的各种钩子。任何可以访问过渡对象的钩子,都可以通过调用`transition.abort()`来立即取消当前过渡,如果保存了该过渡对象,那么在后续可以通过调用`transition.retry()`来重新尝试过渡。

### Preventing Transitions via `willTransition`

### 通过`willTransition`来阻止过渡

When a transition is attempted, whether via `{{link-to}}`, `transitionTo`,
or a URL change, a `willTransition` action is fired on the currently
active routes. This gives each active route, starting with the leaf-most
route, the opportunity to decide whether or not the transition should occur.

当尝试进行过渡时,无论是通过`{{link-to}}``transitionTo`,还是改变URL,都会在当前活动的路由上触发一个`willTransition`操作。这给从页节点开始,每个活动的路由一个可以决定是否发生一个过渡的机会。

Imagine your app is in a route that's displaying a complex form for the user
to fill out and the user accidentally navigates backwards. Unless the
transition is prevented, the user might lose all of the progress they
made on the form, which can make for a pretty frustrating user experience.

假设应用当前在一个提供了复杂的表单给用户填写的路由,用户却不小心回退了。那么除非过渡被阻止,否则用户在表单上的输入将全部丢失,这会导致极差的用户体验。

Here's one way this situation could be handled:

下面是一个可以处理这种情形的方案:

```js
App.FormRoute = Ember.Route.extend({
actions: {
Expand All @@ -38,11 +48,15 @@ App.FormRoute = Ember.Route.extend({

### Aborting Transitions Within `model`, `beforeModel`, `afterModel`

### `model``beforeModel``afterModel`中取消过渡

The `model`, `beforeModel`, and `afterModel` hooks described in
[Asynchronous Routing](/guides/routing/asynchronous-routing)
each get called with a transition object. This makes it possible for
destination routes to abort attempted transitions.

[异步路由](/guides/routing/asynchronous-routing)中描述的`model``beforeModel``afterModel`钩子,每一个被调用时都传入了一个过渡对象。这让目标路由可以取消尝试进行的过渡。

```js
App.DiscoRoute = Ember.Route.extend({
beforeModel: function(transition) {
Expand All @@ -56,11 +70,15 @@ App.DiscoRoute = Ember.Route.extend({

### Storing and Retrying a Transition

### 保存并重试过渡

Aborted transitions can be retried at a later time. A common use case
for this is having an authenticated route redirect the user to a login
page, and then redirecting them back to the authenticated route once
they've logged in.

被取消的过渡可以在之后某一时刻进行重试。一个常见的场景就是有一个身份验证的路由,将未通过验证的用户重定向到登录页面,当用户完成登录后,将用户又定向回之前请求的路由。

```js
App.SomeAuthenticatedRoute = Ember.Route.extend({
beforeModel: function(transition) {
Expand Down
38 changes: 11 additions & 27 deletions source/guides/routing/preventing-and-retrying-transitions.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
During a route transition, the Ember Router passes a transition
object to the various hooks on the routes involved in the transition.
Any hook that has access to this transition object has the ability
to immediately abort the transition by calling `transition.abort()`,
and if the transition object is stored, it can be re-attempted at a
later time by calling `transition.retry()`.
英文原文: [http://emberjs.com/guides/routing/preventing-and-retrying-transitions/](http://emberjs.com/guides/routing/preventing-and-retrying-transitions/)

### Preventing Transitions via `willTransition`
在一个路由过渡过程中,Ember路由器将一个过渡对象传递给过渡相关的路由的各种钩子。任何可以访问过渡对象的钩子,都可以通过调用`transition.abort()`来立即取消当前过渡,如果保存了该过渡对象,那么在后续可以通过调用`transition.retry()`来重新尝试过渡。

When a transition is attempted, whether via `{{link-to}}`, `transitionTo`,
or a URL change, a `willTransition` action is fired on the currently
active routes. This gives each active route, starting with the leaf-most
route, the opportunity to decide whether or not the transition should occur.
### 通过`willTransition`来阻止过渡

Imagine your app is in a route that's displaying a complex form for the user
to fill out and the user accidentally navigates backwards. Unless the
transition is prevented, the user might lose all of the progress they
made on the form, which can make for a pretty frustrating user experience.
当尝试进行过渡时,无论是通过`{{link-to}}``transitionTo`,还是改变URL,都会在当前活动的路由上触发一个`willTransition`操作。这给从页节点开始,每个活动的路由一个可以决定是否发生一个过渡的机会。

Here's one way this situation could be handled:
假设应用当前在一个提供了复杂的表单给用户填写的路由,用户却不小心回退了。那么除非过渡被阻止,否则用户在表单上的输入将全部丢失,这会导致极差的用户体验。

下面是一个可以处理这种情形的方案:

```js
App.FormRoute = Ember.Route.extend({
Expand All @@ -36,12 +27,9 @@ App.FormRoute = Ember.Route.extend({
});
```

### Aborting Transitions Within `model`, `beforeModel`, `afterModel`
### `model``beforeModel``afterModel`中取消过渡

The `model`, `beforeModel`, and `afterModel` hooks described in
[Asynchronous Routing](/guides/routing/asynchronous-routing)
each get called with a transition object. This makes it possible for
destination routes to abort attempted transitions.
[异步路由](/guides/routing/asynchronous-routing)中描述的`model``beforeModel``afterModel`钩子,每一个被调用时都传入了一个过渡对象。这让目标路由可以取消尝试进行的过渡。

```js
App.DiscoRoute = Ember.Route.extend({
Expand All @@ -54,12 +42,9 @@ App.DiscoRoute = Ember.Route.extend({
});
```

### Storing and Retrying a Transition
### 保存并重试过渡

Aborted transitions can be retried at a later time. A common use case
for this is having an authenticated route redirect the user to a login
page, and then redirecting them back to the authenticated route once
they've logged in.
被取消的过渡可以在之后某一时刻进行重试。一个常见的场景就是有一个身份验证的路由,将未通过验证的用户重定向到登录页面,当用户完成登录后,将用户又定向回之前请求的路由。

```js
App.SomeAuthenticatedRoute = Ember.Route.extend({
Expand Down Expand Up @@ -88,4 +73,3 @@ App.LoginController = Ember.Controller.extend({
}
});
```

0 comments on commit 5ad0da2

Please sign in to comment.