vue-router 2 template
Template for vue-router 2
HTML
<script src="https://npmcdn.com/vue/dist/vue.js"></script>
<script src="https://npmcdn.com/vue-router/dist/vue-router.js"></script>
<div id="app">
<router-view></router-view>
</div>
Babel + JSX
const Home = {
data: function(){
return {
arr: ['bar', 'baz']
}
},
methods: {
navigate1: function() {
this.$router.push({query: {foo: this.arr}});
},
navigate2: function() {
this.arr.push('bax')
this.$router.push({query: {foo: this.arr.slice(0)}});
}
},
template: `
<div>
<a href="#" @click.stop="navigate1">?bar-baz</a>
<br><a href="#" @click.stop="navigate2">?bar-baz-bax</a>
<br><br>$route.query: {{ $route.query.foo }}
<br><br>this.arr: {{ this.arr }}
</div>
`
}
const router = new VueRouter({
mode: 'history',
routes: [
{ name: 'home', path: '/:foo(.*)*', component: Home }
]
})
new Vue({
router,
el: '#app',
data: {
msg: 'Hello World'
}
})