diff --git a/src/layout/components/tags.vue b/src/layout/components/tags.vue index 397a8803..d651e6f5 100644 --- a/src/layout/components/tags.vue +++ b/src/layout/components/tags.vue @@ -126,13 +126,14 @@ }, //关闭tag closeSelectedTag(tag, autoPushLatestView=true) { + const nowTagIndex = this.tagList.findIndex(item => item.fullPath == tag.fullPath) this.$store.commit("removeViewTags", tag) this.$store.commit("removeIframeList", tag) this.$store.commit("removeKeepLive", tag.name) if (autoPushLatestView && this.isActive(tag)) { - const latestView = this.tagList.slice(-1)[0] - if (latestView) { - this.$router.push(latestView) + const leftView = this.tagList[nowTagIndex - 1] + if (leftView) { + this.$router.push(leftView) } else { this.$router.push('/') } diff --git a/src/store/modules/viewTags.js b/src/store/modules/viewTags.js index b34f71e6..5946559a 100644 --- a/src/store/modules/viewTags.js +++ b/src/store/modules/viewTags.js @@ -1,13 +1,20 @@ +import router from '@/router' + export default { state: { viewTags: [] }, mutations: { pushViewTags(state, route){ + let backPathIndex = state.viewTags.findIndex(item => item.fullPath == router.options.history.state.back) let target = state.viewTags.find((item) => item.fullPath === route.fullPath) let isName = route.name if(!target && isName){ - state.viewTags.push(route) + if(backPathIndex == -1){ + state.viewTags.push(route) + }else{ + state.viewTags.splice(backPathIndex+1, 0, route) + } } }, removeViewTags(state, route){