1
- # Transition Hooks
1
+ # ใใฉใณใธใทใงใณใใใฏ
2
2
3
- A ` <router-view> ` component involved in a transition can control / react to the transition by implementing appropriate transition pipeline hooks. These hooks include :
3
+ ` <router-view> ` ใณใณใใผใใณใใฏใ้ฉๅใชใใฉใณใธใทใงใณใใคใใฉใคใณใใใฏใๅฎ่ฃ
ใใใใจใซใใฃใฆใใฉใณใธใทใงใณใๅถๅพกใใ(ใซๅๅฟใใ)ใใจใใงใใพใใใใใใฎใใใฏใๅซใพใใพใ :
4
4
5
5
- ` data `
6
6
- ` activate `
@@ -9,11 +9,11 @@ A `<router-view>` component involved in a transition can control / react to the
9
9
- ` canDeactivate `
10
10
- ` canReuse `
11
11
12
- You can implement these hooks under your component's ` route ` option :
12
+ ใใชใใฎใณใณใใผใใณใใฎไธใง ` route ` ใชใใทใงใณใใใใใฎใใใฏใงๅฎ่ฃ
ใใใใจใใงใใพใ :
13
13
14
14
``` js
15
15
Vue .component (' hook-example' , {
16
- // ... other options
16
+ // ... ไปใฎใชใใทใงใณ
17
17
route: {
18
18
activate : function (transition ) {
19
19
console .log (' hook-example activated!' )
@@ -27,80 +27,79 @@ Vue.component('hook-example', {
27
27
})
28
28
```
29
29
30
- ### Transition Object
30
+ ### ใใฉใณใธใทใงใณใชใใธใงใฏใ
31
31
32
- Each transition hook will receive a ` transition ` object as the only argument. The transition object exposes the following properties & methods :
32
+ ใใฉใณใธใทใงใณใใใฏใใจใซๅฏไธๅผๆฐใจใใฆ ` transition ` ใชใใธใงใฏใใๅใๅใใพใใใใฉใณใธใทใงใณใชใใธใงใฏใใฏไปฅไธใฎใใญใใใฃใจใกใฝใใใๅ
ฌ้ใใพใ :
33
33
34
34
- ** transition.from**
35
35
36
- A [ route object ] ( ../route.md ) representing the route we are transitioning from.
36
+ from ใใใใฉใณใธใทใงใณใใฆใใ route ใ่กจใ [ route ใชใใธใงใฏใ ] ( ../route.md ) ใ
37
37
38
38
- ** transition.to**
39
39
40
- A route object representing the target path.
40
+ ใฟใผใฒใใใในใ่กจใ route ใชใใธใงใฏใใ
41
41
42
42
- ** transition.next()**
43
43
44
- Call this method to progress to the next step of the transition.
44
+ ใใฉใณใธใทใงใณใฎๆฌกใฎในใใใใซ้ฒใใใใซใใฎใกใฝใใใๅผใณๅบใใพใใ
45
45
46
46
- ** transition.abort([ reason] )**
47
47
48
- Call this method to cancel / reject the transition.
48
+ ใใฉใณใธใทใงใณใใญใฃใณใปใซ/ๆๅฆใใใซใฏใใฎใกใฝใใใๅผใณๅบใใพใใ
49
49
50
50
- ** transition.redirect(path)**
51
51
52
- Cancel current transition and redirect to a different target route instead.
52
+ ็พ็ถใฎใใฉใณใธใทใงใณใใญใฃใณใปใซใใฆใไปฃใใใซๅฅใฎใฟใผใฒใใ route ใซใชใใคใฌใฏใใใพใใ
53
53
54
- All transition hooks are considered asynchronous by default. In order to signal the transition to progress, you have three options :
54
+ ๅ
จใฆใฎใใฉใณใธใทใงใณใใใฏใฏใใใฉใซใใง้ๅๆใจ่ฆใชใใใพใใใใฉใณใธใทใงใณใฎ้ฒ่กใ้็ฅใใใใใซใ3ใคใฎใชใใทใงใณใใใใพใ :
55
55
56
- 1 . Explicitly call one of ` next ` , ` abort ` or ` redirect ` .
56
+ 1 . ๆ็คบ็ใซ ` next ` ใ ` abort ` ใพใใฏ ` redirect ` ใฎใใใใใๅผใณๅบใใพใใ
57
57
58
- 2 . Return a Promise. Details below.
58
+ 2 . Promise ใ่ฟใใพใใ่ฉณ็ดฐใฏไปฅไธใง่ชฌๆใใพใใ
59
59
60
- 3 . For validation hooks (` canActivate ` and ` canDeactivate ` ), you can synchronously return a Boolean value.
60
+ 3 . ๆค่จผใใใฏ (` canActivate ` ใจ ` canDeactivate ` ) ใงใๅๆ็ใซ Boolean ๅคใ่ฟใใพใใ
61
61
62
- ### Returning Promise in Hooks
62
+ ### ใใใฏใง Promise ใ่ฟใ
63
63
64
- When you return a Promise in a transition hook, ` transition.next ` will be called for you when the Promise resolves. If the Promise is rejected during validation phase, it will call ` transition.abort ` ; if it is rejected during activation phase, it will call ` transition.next ` .
64
+ ใใฉใณใธใทใงใณใใใฏใง Promise ใ่ฟใใจใใ ` transition.next ` ใฏ Promise ใ่งฃๆฑบใใใจใใซๅผใณๅบใใใพใใใใใ Promise ใๆค่จผใใงใผใบใฎ้ใงๆๅฆใใใๅ ดๅใฏใ ` transition.abort ` ใๅผใณใพใใใใใๆดปๆงๅใใงใผใบใฎ้ใงๆๅฆใใใๅ ดๅใฏใ ` transition.next ` ใๅผใณใพใใ
65
65
66
- For validation hooks (` canActivate ` and ` canDeactivate ` ), if the Promise's resolved value is falsy, it will also abort the transition.
66
+ ๆค่จผใใใฏ (` canActivate ` ใจ ` canDeactivate ` )ใงใใใ Promise ใๅฝใจใชใใใๅคใง่งฃๆฑบใใใๅ ดๅใใใฉใณใธใทใงใณใไธญๆญขใใพใใ
67
67
68
- If a rejected promise has an uncaught error, it will be thrown unless you suppress it with the ` suppressTransitionError ` option when creating the router.
68
+ ใใใPromise ใใญใฃใใใใใฆใใชใใจใฉใผใๆๅฆใใๅ ดๅใฏใใซใผใฟใผใไฝๆใใใจใ ` suppressTransitionError ` ใชใใทใงใณใงๆๅถใใชใ้ใในใญใผใใใพใใ
69
69
70
- ** Example :**
70
+ ** ไพ :**
71
71
72
72
``` js
73
- // inside component definition
73
+ // ใณใณใใผใใณใๅฎ็พฉๅ
้จ
74
74
route: {
75
75
canActivate : function () {
76
- // assuming the service returns a Promise that
77
- // resolve to either `true` or `false`.
76
+ // `true` ใพใใฏ `false` ใฎใฉใกใใใง่งฃๆฑบใใ
77
+ // Promise ใ่ฟใใตใผใในใจไปฎๅฎใใพใใ
78
78
return authenticationService .isLoggedIn ()
79
79
},
80
80
activate : function (transition ) {
81
81
return messageService
82
82
.fetch (transition .to .params .messageId )
83
83
.then ((message ) => {
84
- // set the data once it arrives.
85
- // the component will not display until this
86
- // is done.
84
+ // ใใใๅฑใใใใไธๅบฆใ ใใใผใฟใ่จญๅฎใใพใใ
85
+ // ใณใณใใผใใณใใฏใใใ็ตใใใพใง่กจ็คบใใใพใใใ
87
86
this .message = message
88
87
})
89
88
}
90
89
}
91
90
```
92
91
93
- We are asynchronously fetching data in the ` activate ` hook here just for the sake of an example; Note that we also have the [ ` data ` hook ] ( data.md ) which is in general more appropriate for this purpose.
92
+ ใใใงใฏใกใใใฉไพใฎใใ ` activate ` ใใใฏใง้ๅๆ็ใซใใผใฟใใใงใใใใฆใใพใใไธ่ฌ็ใซใฏใใฎ็ฎ็ใฎใใใซใใใ้ฉๅใช [ ` data ` ใใใฏ ] ( data.md ) ใใใใใจใซๆณจๆใใฆใใ ใใใ
94
93
95
- ** TIP:** if you are using ES6 you can use argument destructuring to make your hooks cleaner :
94
+ ** TIP:** ใใใ ES6 ใไฝฟ็จใใฆใใๅ ดๅใใใชใใฎใใใฏใใฏใชใผใณใชใใฎใซใใใใใซใ argument destructuring ใไฝฟ็จใใใใจใใงใใพใ :
96
95
97
96
``` js
98
97
route: {
99
98
activate ({ next }) {
100
- // when done :
99
+ // ใใใจใ :
101
100
next ()
102
101
}
103
102
}
104
103
```
105
104
106
- Check out the [ advanced example] ( https://github.com/vuejs/vue-router/tree/dev/example/advanced ) in the vue-router repo.
105
+ vue-router ใฌใใธใใชใฎ [ advanced example] ( https://github.com/vuejs/vue-router/tree/dev/example/advanced ) ใใใงใใฏใใฆใใ ใใใ
0 commit comments