-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathrouter.js
59 lines (54 loc) · 1.85 KB
/
router.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
import Vue from 'vue'
import VueRouter from 'vue-router'
import RouteOne from './router/RouteOne.vue'
import RouteTwo from './router/RouteTwo.vue'
import RouteWithParams from './router/RouteWithParams.vue'
import NamedRoute from './router/NamedRoute.vue'
import RouteWithQuery from './router/RouteWithQuery.vue'
import RouteWithBeforeEnter from './router/RouteWithBeforeEnter.vue'
import RouteWithAlias from './router/RouteWithAlias.vue'
import RouteWithProps from './router/RouteWithProps.vue'
import ParentRoute from './router/ParentRoute.vue'
import ChildRoute from './router/ChildRoute.vue'
Vue.use(VueRouter)
const DynamicComponent = {
render: h => h('div', 'Hello from dynamic component'),
}
const routes = [
{ path: '/route-one', component: RouteOne },
{ path: '/route-two', component: RouteTwo },
{ path: '/route-with-params/:username/:id', component: RouteWithParams },
{ path: '/route-named', component: NamedRoute, name: 'NamedRoute' },
{ path: '/route-with-query', component: RouteWithQuery },
{
path: '/route-with-before-enter',
component: RouteWithBeforeEnter,
beforeEnter: (to, from, next) => {
next()
},
},
{ path: '/route-with-redirect', redirect: '/route-one' },
{ path: '/route-with-redirect-function', redirect: () => '/route-one' },
{ path: '/route-with-alias', component: RouteWithAlias, alias: '/this-is-the-alias' },
{ path: '/route-with-dynamic-component', component: DynamicComponent, props: true },
{
path: '/route-with-props',
component: RouteWithProps,
props: {
username: 'My Username',
id: 99,
},
},
{ path: '/route-with-props-default', component: RouteWithProps },
{
path: '/route-parent',
component: ParentRoute,
children: [
{ path: '/route-child', component: ChildRoute },
],
},
]
const router = new VueRouter({
routes,
})
export default router