vue-router 2 named views
Example of named views
by WILLIAM CORREA
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">
<div id="app">
<h1>Named Views</h1>
<ul>
<li><router-link to="/">/.</router-link></li>
<li><router-link to="/other">/other</router-link></li>
</ul>
<router-view class="view one"></router-view>
<router-view class="view two" name="a"></router-view>
<router-view class="view three" name="b"></router-view>
</div>
</div>
Babel + JSX
const Header = { template: '<div>Header</div>' }
const ContentA = { template: '<div>Content A</div>' }
const ContentB = { template: '<div>Content B</div>' }
const Footer = { template: '<div>Footer</div>' }
function middleware(Content) {
return {
default: Header,
a: Content,
b: Footer
};
}
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: middleware(ContentA)
},
{
path: '/other',
components: middleware(ContentB)
}
]
})
new Vue({
router,
el: '#app'
});