@@ -5,6 +5,7 @@ import { defineStore } from 'pinia'
55import { ref , watchEffect } from 'vue'
66import pathInfo from '@/pathInfo.json'
77import { useRoute } from "vue-router" ;
8+ import { config } from "@/core/config.js" ;
89
910const notLayoutRouterArr = [ ]
1011const keepAliveRoutersArr = [ ]
@@ -55,24 +56,24 @@ export const useRouterStore = defineStore('router', () => {
5556
5657 // 1. 首先添加原有的keepAlive配置
5758 keepArrTemp . push ( ...keepAliveRoutersArr )
58-
59- history . forEach ( ( item ) => {
60- // 2. 为所有history中的路由强制启用keep-alive
61- // 通过routeMap获取路由信息,然后通过pathInfo获取组件名
62- const routeInfo = routeMap [ item . name ]
63- if ( routeInfo && routeInfo . meta && routeInfo . meta . path ) {
64- const componentName = pathInfo [ routeInfo . meta . path ]
65- if ( componentName ) {
66- keepArrTemp . push ( componentName )
59+ if ( config . KeepAliveTabs ) {
60+ history . forEach ( ( item ) => {
61+ // 2. 为所有history中的路由强制启用keep-alive
62+ // 通过routeMap获取路由信息,然后通过pathInfo获取组件名
63+ const routeInfo = routeMap [ item . name ]
64+ if ( routeInfo && routeInfo . meta && routeInfo . meta . path ) {
65+ const componentName = pathInfo [ routeInfo . meta . path ]
66+ if ( componentName ) {
67+ keepArrTemp . push ( componentName )
68+ }
6769 }
68- }
69-
70- // 3. 如果子路由在tabs中打开,父路由也需要keepAlive
71- if ( nameMap [ item . name ] ) {
72- keepArrTemp . push ( nameMap [ item . name ] )
73- }
74- } )
75-
70+
71+ // 3. 如果子路由在tabs中打开,父路由也需要keepAlive
72+ if ( nameMap [ item . name ] ) {
73+ keepArrTemp . push ( nameMap [ item . name ] )
74+ }
75+ } )
76+ }
7677 keepAliveRouters . value = Array . from ( new Set ( keepArrTemp ) )
7778 }
7879
0 commit comments