Skip to content

Commit 8ebcc3c

Browse files
committed
docs: transition
1 parent 1a91987 commit 8ebcc3c

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

docs/en/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- [Server Config for History Mode](essentials/server.md)
1616
- Advanced
1717
- [Navigation Hooks](advanced/navigation-guards.md)
18-
- [Animations](advanced/animations.md)
18+
- [Transitions](advanced/transitions.md)
1919
- [Data Fetching](advanced/data-fetching.md)
2020
- [Scroll Behavior](advanced/scroll-behavior.md)
2121
- [Lazy Loading](advanced/lazy-loading.md)

docs/en/advanced/animations.md

Whitespace-only changes.

docs/en/advanced/transitions.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Transitions
2+
3+
Since the `<router-view>` is essentially a dynamic component, we can apply transition effects to it the same way using the `<transition>` component:
4+
5+
``` html
6+
<transition>
7+
<router-view></router-view>
8+
</transition>
9+
```
10+
11+
[Everything about `<transition>`](http://vuejs.org/guide/transitions.html) works the same here.
12+
13+
### Per-Route Transition
14+
15+
The above usage will apply the same transition for all routes. If you want each route's component to have different transitions, you can instead use `<transition>` with different names inside each route component:
16+
17+
``` js
18+
const Foo = {
19+
template: `
20+
<transition name="slide">
21+
<div class="foo">...</div>
22+
</transition>
23+
`
24+
}
25+
26+
const Bar = {
27+
template: `
28+
<transition name="fade">
29+
<div class="bar">...</div>
30+
</transition>
31+
`
32+
}
33+
```
34+
35+
### Route-Based Dynamic Transition
36+
37+
It is also possible to determine the transition to use dynamically based on the relationship between the target route and current route:
38+
39+
``` html
40+
<!-- use a dynamic transition name -->
41+
<transition :name="transitionName">
42+
<router-view></router-view>
43+
</transition>
44+
```
45+
46+
``` js
47+
// then, in the parent component,
48+
// watch the $route to determine the transition to use
49+
watch: {
50+
'$route' (to, from) {
51+
const toDepth = to.path.split('/').length
52+
const fromDepth = from.path.split('/').length
53+
this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
54+
}
55+
}
56+
```
57+
58+
See full example [here](https://github.com/vuejs/vue-router/blob/next/examples/transitions/app.js).

0 commit comments

Comments
 (0)