forked from vuejs/vue-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
105 lines (96 loc) · 2.32 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const Wrap = { template: '<div>child: <router-view></router-view></div>' }
const Index = {
template: '<wrap />',
components: {
Wrap
}
}
const WithGuard = {
template: '<div>{{ $route.name }}: {{ n }}</div>',
data: () => ({ n: 0 }),
beforeRouteEnter (to, from, next) {
next(vm => {
vm.n++
})
}
}
const IndexChild1 = { template: '<div>index child1</div>' }
const IndexChild2 = { template: '<div>index child2</div>' }
const Home = { template: '<div>home</div>' }
const ViewWithKeepalive = { template: '<keep-alive><router-view></router-view></keep-alive>' }
const router = new VueRouter({
mode: 'history',
base: __dirname,
routes: [
{
path: '/index',
component: Index,
children: [
{
path: 'child1',
component: IndexChild1
},
{
path: 'child2',
component: IndexChild2
}
]
},
{
path: '/home',
component: Home
},
{
path: '/with-guard1',
name: 'with-guard1',
component: WithGuard
},
{
path: '/with-guard2',
name: 'with-guard2',
component: WithGuard
},
{
path: '/one',
component: ViewWithKeepalive,
children: [
{
path: 'two',
component: ViewWithKeepalive,
children: [
{
path: 'child1',
component: IndexChild1
},
{
path: 'child2',
component: IndexChild2
}
]
}
]
}
]
})
new Vue({
router,
template: `
<div id="app">
<ul>
<li><router-link to="/index/child1">/index/child1</router-link></li>
<li><router-link to="/index/child2">/index/child2</router-link></li>
<li><router-link to="/home">/home</router-link></li>
<li><router-link to="/with-guard1">/with-guard1</router-link></li>
<li><router-link to="/with-guard2">/with-guard2</router-link></li>
<li><router-link to="/one/two/child1">/one/two/child1</router-link></li>
<li><router-link to="/one/two/child2">/one/two/child2</router-link></li>
</ul>
<keep-alive>
<router-view class="view"></router-view>
</keep-alive>
</div>
`
}).$mount('#app')