vue-router 2 named views

Example of named views

by Theara Yuom

HTML

<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

<div id="app">
  <h1>Named Views</h1>
  <ul>
    <li>
      <router-link to="/">/foo</router-link>
    </li>
  </ul>
  <router-view class="view one"></router-view>
  <router-view class="view two" name="a"></router-view>
</div>

Babel + JSX

const Foo = { template: '<div>foo <br><router-link to="/other">/other</router-link></div>' }
const Bar = { template: '<div>bar</div>' }
const Baz = { template: '<div>baz</div>' }

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '/',
      // a single route can define multiple named components
      // which will be rendered into <router-view>s with corresponding names.
      components: {
        default: Foo,
      }
    },
    {
      path: '/other',
      components: {
        default: Foo,
        a: Bar,
      }
    }
  ]
})

new Vue({
	router,
  el: '#app'
})