Skip to content

Commit fb80f8f

Browse files
authored
feat: add closeAllTabs
feat: add closeAllTabs
2 parents 8047bb1 + 573ff34 commit fb80f8f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.changeset/red-fishes-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@alita/plugins': patch
3+
---
4+
5+
closeAllTabs can be used to close all keepalive tabs

packages/plugins/src/keepalive.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function closeTab(path: string) {
9494
path
9595
}});
9696
}
97+
export function closeAllTabs() {
98+
keepaliveEmitter.emit({type:'closeAllTabs'});
99+
}
97100
`,
98101
});
99102
// index.ts for export
@@ -102,7 +105,7 @@ export function closeTab(path: string) {
102105
path: `${DIR_NAME}/index.tsx`,
103106
content: `
104107
export { KeepAliveContext,useKeepOutlets } from './context';
105-
export { dropByCacheKey, closeTab } from './support';
108+
export { dropByCacheKey, closeTab, closeAllTabs } from './support';
106109
`,
107110
});
108111
});

packages/plugins/templates/keepalive/context.tpl

+9
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ export function useKeepOutlets() {
198198
navigate(`${pathname}${search}${hash}`);
199199
}
200200
};
201+
const closeAllTabs = () => {
202+
const pathList = Object.keys(keepElements.current);
203+
pathList.forEach(targetKey => {
204+
dropByCacheKey(targetKey?.toLowerCase());
205+
});
206+
};
201207
const navigate = useNavigate();
202208
{{#isPluginModelEnable}}
203209
const localConfig = React.useMemo(() => {
@@ -275,6 +281,9 @@ export function useKeepOutlets() {
275281
case 'closeTab':
276282
closeTab(payload?.path?.toLowerCase());
277283
break;
284+
case 'closeAllTabs':
285+
closeAllTabs();
286+
break;
278287
{{/hasTabsLayout}}
279288
default:
280289
break;

0 commit comments

Comments
 (0)