Skip to content

Commit

Permalink
fix: setting redirect after refresh page router push bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Jul 9, 2024
1 parent 58ee531 commit 6a7c0ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/layout/components/columns/ma-columns-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
>
<li
:class="`${classStyle}`"
@click="loadMenu(bigMenu, index)"
@click="() => {
keepAliveStore.menuLoader = false
loadMenu(bigMenu, index)
}"
>
<component v-if="bigMenu.meta.icon" :is="bigMenu.meta.icon" class="text-xl mt-1" />
<span
Expand Down Expand Up @@ -46,24 +49,27 @@
import { useRoute, useRouter } from 'vue-router'
import MaMenu from '../ma-menu.vue'

import { useAppStore, useUserStore } from '@/store'
import { useAppStore, useUserStore, useKeepAliveStore } from '@/store'

const route = useRoute()
const router = useRouter()

const MaMenuRef = ref(null)
const appStore = useAppStore()
const userStore = useUserStore()
const keepAliveStore = useKeepAliveStore()
const showMenu = ref(false)

const title = ref('')
const classStyle = ref('flex flex-col parent-menu items-center rounded mt-1 text-gray-200 hover:bg-gray-700 dark:hover:text-gray-50 dark:hover:bg-blackgray-1')

onMounted(() => {
keepAliveStore.menuLoader = true
initMenu(true)
})

watch(() => route, v => {
keepAliveStore.menuLoader = false
initMenu(false)
}, { deep: true })

Expand All @@ -74,6 +80,7 @@
} else {
current = 'home'
}
console.log(current)
if (userStore.routers && userStore.routers.length > 0) {
userStore.routers.map((item, index) => {
if (item.name == current) loadMenu(item, index, init)
Expand All @@ -87,7 +94,7 @@
return
}
if (bigMenu.children.length > 0) {
if (bigMenu.redirect && isInit) {
if (bigMenu.redirect && isInit && !keepAliveStore.menuLoader) {
router.push(bigMenu.redirect)
}
MaMenuRef.value.loadChildMenu(bigMenu)
Expand Down
12 changes: 9 additions & 3 deletions src/layout/components/mixed/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
<span class="ml-2 text-xl mt-2.5 hidden md:block">{{ $title }}</span>
</div>
<div class="flex justify-between w-full layout-banner">
<top-menu v-model="userStore.routers" :active="active" @go="loadMenu" ref="topMenuRef" />
<top-menu v-model="userStore.routers" :active="active" @go="(bigMenu, index) => {
keepAliveStore.menuLoader = false
loadMenu(bigMenu, index)
}" ref="topMenuRef" />
<ma-operation />
</div>
</a-layout-header>
Expand All @@ -42,7 +45,7 @@

<script setup>
import { ref, watch, onMounted } from 'vue'
import { useAppStore, useUserStore } from '@/store'
import { useAppStore, useUserStore, useKeepAliveStore } from '@/store'
import { useRoute, useRouter } from 'vue-router'
import ResizeObserver from 'resize-observer-polyfill'
import MaOperation from '../ma-operation.vue'
Expand All @@ -58,14 +61,17 @@
const MaMenuRef = ref(null)
const userStore = useUserStore()
const appStore = useAppStore()
const keepAliveStore = useKeepAliveStore()
const showMenu = ref(false)
const active = ref()

onMounted(() => {
keepAliveStore.menuLoader = true
initMenu(true)
})

watch(() => route, v => {
keepAliveStore.menuLoader = false
initMenu(false)
}, { deep: true })

Expand All @@ -88,7 +94,7 @@
return
}
if (bigMenu.children.length > 0) {
if (bigMenu.redirect && isInit) {
if (bigMenu.redirect && isInit && !keepAliveStore.menuLoader) {
router.push(bigMenu.redirect)
}
MaMenuRef.value.loadChildMenu(bigMenu)
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/keepAlive.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { defineStore } from 'pinia'
const useKeepAliveStore = defineStore('keepAlive', {
state: () => ({
keepAlives: [],
show: true
show: true,
menuLoader: false,
}),

getters: {
Expand Down

0 comments on commit 6a7c0ac

Please sign in to comment.