I have searched in lots of parts of Internet (stackoverflow,vue documentation, blogs, etc.) and I haven´t found the solution that I need. So, the issue is the following:
routes.js
{
path:'/',
components:{
allPageView:LytSPA
},
meta:{
requiresAuth:true
},
children:[
{
path:'',
name:'admin',
components:{
sectionView:AdminDashboard
}
},
{
name:'admin.users',
path:'usuarios',
components:{
sectionView:Users
},
children:[
{
name:'admin.users.create',
path:'crear',
components:{
sectionView:UsersCreateEdit
}
}
]
}]}
So, the paths are: / , /usuarios and /usuarios/crear.
My views are: App.vue (with a named view), LytSPA.vue (with a named view), AdminDashboard.vue, Users.vue, UsersCreateEdit. So, I have 2 node views and 3 leaf views.
App.vue
<template>
<router-view name="allPageView"></router-view></template>
LytSPA.vue
<template>
<div>
<header>
<header-view></header-view>
</header>
<transition name="slide-left-aside">
<aside v-show="!collapsed">
<aside-view @collapse="collapseAside"></aside-view>
</aside>
</transition>
<transition name="slide-expand-button">
<b-button @click="collapseAside(false)" id="btnExpand" v-show="collapsed">
<font-awesome-icon icon="chevron-right"/>
</b-button>
</transition>
<section id="sectionSPA" :class="{collapsed: collapsed}">
<breadcrumb-view></breadcrumb-view>
<router-view name="sectionView" key="$route.fullPath"></router-view>
</section>
</div></template>
As you can see, in LayoutSPA.vue I dropped my main views in the container sectionView, thus:
- when the path is / load the Dashboard view.
- when the path is /usuarios load the Users view.
And here comes the problem, when the path is /usuarios/crear, it either doesn´t load the UsersCreateEdit view or it keeps the last one (Users.vue). However, the routing is working because I put a redirect validation for unknown URLs, since the url usuarios/crear doesn´t change so that's work but doesn´t load the view.
I have already worked of this way with UI-Router in AngularJS and there wasn´t any problem because it works with inheritance of states, but I want to know if exists any way to do the same in Vue???
Note: I have an alternative solution but I don´t like it, because I have to put the admin.users.create route as a sibling of admin.users and it works but I need that it be nested because I need to retrieve the matched routes to build my breadcrumb and I don't want to parse the path to build it.