vue-router 2 template

Template for vue-router 2

by Sarah Godoshian

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-link to="/">/home</router-link>
  <router-link to="/foo">/foo</router-link>
  <router-link to="/foo/bar">/bar</router-link>
  <router-view></router-view>
  <pre>
    {{ JSON.stringify($route.matched, null, 2) }}
  </pre>
</div>

Babel + JSX

const Home = { template: '<div>Home</div>' }
const Foo = { template: '<div>Foo</div>' }
const Bar = { template: '<div>Bar</div>' }

let routes = [
    { path: '/', component: Home },
    { path: '/foo', component: Foo },
    { path: '/foo/bar', component: Bar }
  ]
  
/* routes = [
    { path: '/', component: Home },
    { path: '/foo', component: Foo,
      children: [
        {
          path: 'bar',
          component: Bar,
        },
      ]
    }
  ] */

const router = new VueRouter({
  mode: 'history',
  routes
})

new Vue({
	router,
  el: '#app',
  data: {
    msg: 'Hello World'
  }
})