How to use data from the Vue instance in the templates of Vue Router routes.
This is my code
HTML
<div id="app">
<router-link to="/foo/1">ruta 1</router-link>
<router-link to="/foo/2">ruta 2</router-link>
<router-view></router-view>
</div>
Javascript
Vue.use(VueRouter);
const Ruta1 = { template: '<div>{{ $route.params.numruta }}</div>' };
const Ruta2 = { template: '<div>{{ $route.params.id }}</div>' };
const router = new VueRouter({
routes: [
{ path: '/foo/:numruta', component: Ruta1 },
{ path: '/foo/:numruta', component: Ruta2 }
]
});
const app = new Vue({
router,
el: "#app",
data:{
usuario:"nombre de usuario"
}
}).$mount('#app');
In that case, use the usuario
element in the templpate
of Ruta1