File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed
Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -18,12 +18,7 @@ export function useRouterPush(inSetup = true) {
1818
1919 const routerBack = router . back ;
2020
21- interface RouterPushOptions {
22- query ?: Record < string , string > ;
23- params ?: Record < string , string > ;
24- }
25-
26- async function routerPushByKey ( key : RouteKey , options ?: RouterPushOptions ) {
21+ async function routerPushByKey ( key : RouteKey , options ?: App . Global . RouterPushOptions ) {
2722 const { query, params } = options || { } ;
2823
2924 const routeLocation : RouteLocationRaw = {
@@ -67,7 +62,7 @@ export function useRouterPush(inSetup = true) {
6762 async function toLogin ( loginModule ?: UnionKey . LoginModule , redirectUrl ?: string ) {
6863 const module = loginModule || 'pwd-login' ;
6964
70- const options : RouterPushOptions = {
65+ const options : App . Global . RouterPushOptions = {
7166 params : {
7267 module
7368 }
Original file line number Diff line number Diff line change @@ -160,6 +160,25 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
160160 update ( ) ;
161161 }
162162
163+ const { routerPushByKey } = useRouterPush ( ) ;
164+ /**
165+ * Replace tab
166+ *
167+ * @param key Route key
168+ * @param options Router push options
169+ */
170+ async function replaceTab ( key : RouteKey , options ?: App . Global . RouterPushOptions ) {
171+ const oldTabId = activeTabId . value ;
172+
173+ // push new route
174+ await routerPushByKey ( key , options ) ;
175+
176+ // remove old tab (exclude fixed tab)
177+ if ( ! isTabRetain ( oldTabId ) ) {
178+ await removeTab ( oldTabId ) ;
179+ }
180+ }
181+
163182 /**
164183 * Switch route by tab
165184 *
@@ -282,6 +301,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
282301 removeTab,
283302 removeActiveTab,
284303 removeTabByRouteName,
304+ replaceTab,
285305 clearTabs,
286306 clearLeftTabs,
287307 clearRightTabs,
Original file line number Diff line number Diff line change @@ -175,6 +175,12 @@ declare namespace App {
175175 type RoutePath = import ( '@elegant-router/types' ) . RoutePath ;
176176 type LastLevelRouteKey = import ( '@elegant-router/types' ) . LastLevelRouteKey ;
177177
178+ /** The router push options */
179+ type RouterPushOptions = {
180+ query ?: Record < string , string > ;
181+ params ?: Record < string , string > ;
182+ } ;
183+
178184 /** The global header props */
179185 interface HeaderProps {
180186 /** Whether to show the logo */
You can’t perform that action at this time.
0 commit comments