I'm trying to create a route with a modal and when you access with router-link to this router-path appears a modal above the current page or if i access directly from url appears the index with modal above.
For example: I'm in http://localhost/profile/1 and click in the sidebar Create team the url changes to http://localhost/team/create but the page behind the modal still is http://localhost/profile/1.
This is the code i'm trying:
router:
Vue.component('modal', Modal);
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'Hello',
component: require('@/components/Hello'),
meta: { auth: false }
},
{
path: '/team',
name: 'team',
component: require('@/components/team/Index'),
meta: { auth: true },
},
{
path: '/team/create',
name: 'CreateTeam',
components: {
b: CreateTeam
},
meta: { auth: true }
},
]
})
App.vue
<template>
<router-view></router-view>
<!-- This is the "MODAL" router-view -->
<router-view name="b"></router-view>
</template>
Modal.vue
<template>
<div class="modal">
<slot name="body"></slot>
<button type="button" @click="$emit('close')">×</button>
</div>
</template>
CreateTeam.vue
<template>
<modal @close="vm.$router.go(-1)">
<div slot="body" class="col-md-12">
<!-- Form here -->
</div>
</modal>
</template>
Everything is working instead that when i go to /create/team behind the modal is empty
If anyone needs this solution, i solved this way:
I created a component create-team Vue.component('create-team',CreateTeam) and i put it in the App.vue like this:
In the same App.vue i created a computed with a vuex getter:
In Sidebar i created a link like this:
And a method CreateTeam
The store.js vuex is simple:
And the last thing is in the CreateTeam.vue component the Close method i made somthing like this:
Maybe someone can make it better, that's my little piece of help
Greetings