@@ -10,6 +10,15 @@ Vue.use(VueRouter)
10
10
const Home = { template: '<div>home</div>' }
11
11
const Foo = { template: '<div>foo</div>' }
12
12
const Bar = { template: '<div>bar</div>' }
13
+ const Foobar = {
14
+ template: `
15
+ <div>
16
+ <p>prop: {{fooParam}}</p>
17
+ <p>params: {{$route.params}}</p>
18
+ </div>'
19
+ `,
20
+ props: ['fooParam']
21
+ }
13
22
14
23
// 3. Create the router
15
24
const router = new VueRouter({
@@ -18,14 +27,21 @@ const router = new VueRouter({
18
27
routes: [
19
28
{ path: '/', component: Home },
20
29
{ path: '/foo', component: Foo },
21
- { path: '/bar', component: Bar }
30
+ { path: '/bar', component: Bar },
31
+ { path: '/foobar/:fooParam?', component: Foobar, props: true }
22
32
]
23
33
})
24
34
25
35
// 4. Create and mount root instance.
26
36
// Make sure to inject the router.
27
37
// Route components will be rendered inside <router-view>.
28
38
new Vue({
39
+ mounted() {
40
+ setTimeout(() => {
41
+ alert('Navigating to `/foobar` with params')
42
+ this.$router.push({ path: '/foobar', params: { fooParam: 'FooBar' } });
43
+ }, 2000);
44
+ },
29
45
router,
30
46
template: `
31
47
<div id="app">
@@ -37,6 +53,7 @@ new Vue({
37
53
<router-link tag="li" to="/bar" :event="['mousedown', 'touchstart']">
38
54
<a>/bar</a>
39
55
</router-link>
56
+ <li><router-link to="/foobar/someParameterValue">/foobar/someParameterValue</router-link></li>
40
57
</ul>
41
58
<router-view class="view"></router-view>
42
59
</div>
0 commit comments