JSFiddle - React, Tailwind, and code Playground
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/profile">/user/foo/profile</router-link>
<router-link to="/user/foo/posts">/user/foo/posts</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 UserHome = {
template: '<div>Home {{ myDataObject.name }}</div>' ,
data: function () {
return {
myDataObject : {name : "Foo" , profile : "Profile Data", posts : "Posts Data" } //How do I get these values down to the children?
}
}
}
const UserProfile = {
template: '<div>Profile {{ $route.params.id }} {{ profile }} </div>',
props: ["myDataObject"],
data: function() {
//return profile : myDataObject.profile
}
}
const UserPosts = { template: '<div>Posts {{ $route.params.id }}</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 },
// UserProfile will be rendered inside User's <router-view>
// when /user/:id/profile is matched
{ path: 'profile', component: UserProfile },
// UserPosts will be rendered inside User's <router-view>
// when /user/:id/posts is matched
{ path: 'posts', component: UserPosts }
]
}
]
})
const app = new Vue({ router }).$mount('#app')