Вы можете использовать meta
для установки / получения других данных, как показано в примере ниже по ссылке
Live Fiddle
Я использую this.$parent.title
для изменения заголовка.
const http404 = {
template: '<div>http404 path is : {{$route.path}}</div>',
mounted(){
console.log(this.$route.path);
this.$parent.title ="http404 Page";
}
}
const index = {
template: '<div>index path is : {{$route.path}}</div>',
mounted(){
this.$parent.title ="Index Page";
console.log(this.$route.path);
}
}
const panda = {
template: '<div>panda path is : {{$route.path}}</div>',
mounted(){
this.$parent.title ="panda Page";
console.log(this.$route.path);
}
}
const router = new VueRouter({
mode: 'history',
routes: [
{
path: "/",
name: "root",
redirect: '/index'
},
{
path: "/index",
name: "index",
component: index
},
{
path: "/panda",
name: "panda",
component: panda
},
//...
{
path: "**",
name: "http404",
component: http404
}
]
})
new Vue({
router,
el: '#app',
data:{
title:"NA"
}
})
<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>Page : {{title}}</div>
<router-link to="/">Root</router-link> |
<router-link to="/index">Index</router-link> |
<router-link to="/panda">Panda</router-link> |
<router-link to="/http404">http404</router-link>
<router-view></router-view>
</div>