src/store/modules/route.js
import layout from '@/views/layout/index.vue'
import router from '@/router'
let routes = [{
path: '/',
component: layout,
redirect: 'index',
children: [{
path: '/xxx',
name: 'xxx',
component: () => import('@/views/xxx/XXX.vue'),
meta: {
title: 'XXX',
noCache: true
}
}]
},
...
]
export const authRoutes = [{}]
export default {
state: {
routes: routes
},
actions: {
add_route({ commit }, data) {
commit('Add_ROUTE', data)
}
}
}
src/store/getters.js
export default {
...
routes: state => state.toute.routes
...
}
src/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import route from '@store/modules/route.js'
import getters from '@store/getters.js'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
route,
...
},
getters
})
src/router/index.js:
import Vue from 'Vue'
import Router from 'vue-router'
import store from '@store/index'
Vue.use(Router)
export default new Router({
// mode: ''hash,
routes: store.getter.routes
})