JSFiddle - React, Tailwind, and code Playground
by Simon060694
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">
<p>
<router-link to="/user/foo">/user/foo</router-link>
<router-link to="/user/foo/contact/list"> Without component</router-link>
<router-link to="/user/foo/contacts/list"> With component</router-link>
</p>
<router-view></router-view>
</div>
Babel + JSX
const User = {
template: `
<div class="user">
<h2>User {{ $route.params.id }}</h2>
<router-view></router-view>
</div>
`
}
const UserContacts = {
template: `
<div class="user">
<h2>User Contacts list</h2>
<router-view></router-view>
</div>
`
}
const UserContact = {
template: `
<div class="user">
<h4>User Contacts {{ $route.params.id }}</h4>
</div>
`
}
const UserHome = { template: '<div>Home</div>' }
const UserProfile = { template: '<div>Profile</div>' }
const UserPosts = { template: '<div>Posts</div>' }
const router = new VueRouter({
routes: [
{ path: '/user/:id', component: User,
children: [
// UserHome will be rendered inside User's <router-view>
// when /user/:id is matched
{ path: '', component: UserHome },
{
path: 'contacts',
component: UserContacts,
children:[
{ path: 'list', component: UserContact },
]
},
{
path: 'contact',
children:[
{ path: 'list', component: UserContact },
]
},
]
}
]
})
const app = new Vue({ router }).$mount('#app')