Answer the question
In order to leave comments, you need to log in
How to completely separate modules in Vue?
There are several roles on the project, and each has its own sections that do not communicate with sections of other roles.
Roughly speaking, the admin role has its own set of pages, the customer role has its own set of pages.
I want to completely separate the section of each role, including the router.
So that after authorization, the root component for all roles (Dashboard.vue) loads the required component through (components: Admin/index.vue and Customer/index.vue), which would already store routes and dynamically connected sections.
I threw in an approximate structure, which, as it seemed to me, should work:
<template>
<div>
<component :is="module" />
</div>
</template>
<script>
export default {
computed: {
module ({ role }) {
if (role === 'admin') {
return () => import('@/views/Dashboard/Admin')
}
if (role === 'customer') {
return () => import('@/views/Dashboard/Customer')
}
return null
}
},
}
</script>
<template>
<div>
<router-view />
</div>
</template>
<script>
import VueRouter from 'vue-router'
import Vue from 'vue'
Vue.use(VueRouter)
export default {
router: new VueRouter({
base: '/',
mode: 'history',
routes: [
{
path: '/',
redirect: { name: 'widget' },
children: [
{
path: 'widget',
name: 'widget',
component: () => import('@/views/Dashboard/Customer/CustomerWidget'),
},
],
},
],
}),
}
</script>
{
path: '/',
name: 'dashboard',
component: () => import('@/views/Dashboard'),
},
<router-view />
, while the page is completely empty, i.e. <router-view />
doesn't hit anything I Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question