🐛 修复路由出现404的问题

dev
smallchill 5 years ago
parent c1ac619afa
commit 9ec5d8506a
  1. 4
      src/page/index/sidebar/index.vue
  2. 9
      src/router/avue-router.js
  3. 43
      src/store/modules/user.js

@ -33,7 +33,7 @@
return {}; return {};
}, },
created() { created() {
this.index.openMenu(this.menuId); this.index.openMenu();
}, },
computed: { computed: {
...mapGetters(["website", "menu", "tag", "keyCollapse", "screen", "menuId"]), ...mapGetters(["website", "menu", "tag", "keyCollapse", "screen", "menuId"]),
@ -41,8 +41,6 @@
return this.$router.$avueRouter.getValue(this.$route); return this.$router.$avueRouter.getValue(this.$route);
} }
}, },
mounted() {
},
methods: {} methods: {}
}; };
</script> </script>

@ -26,7 +26,6 @@ RouterPlugin.install = function (vue, option = {}) {
this.$router.$avueRouter = { this.$router.$avueRouter = {
//全局配置 //全局配置
$website: this.$store.getters.website, $website: this.$store.getters.website,
routerList: [],
group: '', group: '',
meta: {}, meta: {},
safe: this, safe: this,
@ -110,8 +109,6 @@ RouterPlugin.install = function (vue, option = {}) {
for (let i = 0; i < aMenu.length; i++) { for (let i = 0; i < aMenu.length; i++) {
// 取到当前要处理的一项 // 取到当前要处理的一项
const oMenu = aMenu[i]; const oMenu = aMenu[i];
// 判断this.routerList中是否已经存在该path,存在就跳出
if (this.routerList.includes(oMenu[propsDefault.path])) return;
// 这一块的赋值 也就是取到返回的值 // 这一块的赋值 也就是取到返回的值
let path = (() => { let path = (() => {
if (first) { if (first) {
@ -191,11 +188,7 @@ RouterPlugin.install = function (vue, option = {}) {
// for循环结束 // for循环结束
// 这个first 卡的其实就是首路由 // 这个first 卡的其实就是首路由
if (first) { if (first) {
window.console.log(aRouter) this.safe.$router.addRoutes(aRouter)
if (!this.routerList.includes(aRouter[0][propsDefault.path])) {
this.safe.$router.addRoutes(aRouter)
this.routerList.push(aRouter[0][propsDefault.path])
}
} else { } else {
// 这里返回的是子组件 // 这里返回的是子组件
return aRouter return aRouter

@ -38,8 +38,8 @@ const user = {
userInfo: getStore({name: 'userInfo'}) || [], userInfo: getStore({name: 'userInfo'}) || [],
permission: getStore({name: 'permission'}) || {}, permission: getStore({name: 'permission'}) || {},
roles: [], roles: [],
menuId: {},
menu: getStore({name: 'menu'}) || [], menu: getStore({name: 'menu'}) || [],
menuId: getStore({name: 'menuId'}) || [],
menuAll: getStore({name: 'menuAll'}) || [], menuAll: getStore({name: 'menuAll'}) || [],
token: getStore({name: 'token'}) || '', token: getStore({name: 'token'}) || '',
refreshToken: getStore({name: 'refreshToken'}) || '', refreshToken: getStore({name: 'refreshToken'}) || '',
@ -134,8 +134,7 @@ const user = {
logout().then(() => { logout().then(() => {
commit('SET_TOKEN', ''); commit('SET_TOKEN', '');
commit('SET_MENU', []); commit('SET_MENU', []);
commit('SET_MENU_ID', {}); commit('SET_MENU_ALL_NULL', []);
commit('SET_MENU_ALL', []);
commit('SET_ROLES', []); commit('SET_ROLES', []);
commit('SET_TAG_LIST', []); commit('SET_TAG_LIST', []);
commit('DEL_ALL_TAG'); commit('DEL_ALL_TAG');
@ -152,8 +151,7 @@ const user = {
FedLogOut({commit}) { FedLogOut({commit}) {
return new Promise(resolve => { return new Promise(resolve => {
commit('SET_TOKEN', ''); commit('SET_TOKEN', '');
commit('SET_MENU_ID', {}); commit('SET_MENU_ALL_NULL', []);
commit('SET_MENU_ALL', []);
commit('SET_MENU', []); commit('SET_MENU', []);
commit('SET_ROLES', []); commit('SET_ROLES', []);
commit('SET_TAG_LIST', []); commit('SET_TAG_LIST', []);
@ -208,33 +206,24 @@ const user = {
}, },
SET_MENU_ID(state, menuId) { SET_MENU_ID(state, menuId) {
state.menuId = menuId; state.menuId = menuId;
setStore({name: 'menuId', content: state.menuId})
}, },
SET_MENU_ALL: (state, menuAll) => { SET_MENU_ALL: (state, menuAll) => {
state.menuAll = menuAll let menu = state.menuAll;
setStore({name: 'menuAll', content: state.menuAll}) menuAll.forEach(ele => {
if (!menu.find(item => item.label === ele.label && item.path === ele.path)) {
menu.push(ele);
}
})
state.menuAll = menu
setStore({ name: 'menuAll', content: state.menuAll })
},
SET_MENU_ALL_NULL: (state) => {
state.menuAll = []
setStore({ name: 'menuAll', content: state.menuAll })
}, },
SET_MENU: (state, menu) => { SET_MENU: (state, menu) => {
state.menu = menu state.menu = menu
setStore({name: 'menu', content: state.menu}) setStore({ name: 'menu', content: state.menu })
if (validatenull(menu)) return;
//合并动态路由去重
let menuAll = state.menuAll;
menuAll = menuAll.concat(menu).reverse();
let newMenu = [];
for (let item1 of menuAll) {
let flag = true;
for (let item2 of newMenu) {
if (item1.name === item2.name || item1.path === item2.path) {
flag = false;
}
}
if (flag) {
newMenu.push(item1);
}
}
state.menuAll = newMenu;
setStore({name: 'menuAll', content: state.menuAll})
}, },
SET_REFRESH_TOKEN: (state, refreshToken) => { SET_REFRESH_TOKEN: (state, refreshToken) => {
setRefreshToken(refreshToken) setRefreshToken(refreshToken)

Loading…
Cancel
Save