File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -18,12 +18,7 @@ export function useRouterPush(inSetup = true) {
18
18
19
19
const routerBack = router . back ;
20
20
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 ) {
27
22
const { query, params } = options || { } ;
28
23
29
24
const routeLocation : RouteLocationRaw = {
@@ -67,7 +62,7 @@ export function useRouterPush(inSetup = true) {
67
62
async function toLogin ( loginModule ?: UnionKey . LoginModule , redirectUrl ?: string ) {
68
63
const module = loginModule || 'pwd-login' ;
69
64
70
- const options : RouterPushOptions = {
65
+ const options : App . Global . RouterPushOptions = {
71
66
params : {
72
67
module
73
68
}
Original file line number Diff line number Diff line change @@ -160,6 +160,24 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
160
160
update ( ) ;
161
161
}
162
162
163
+ const { routerPushByKey } = useRouterPush ( ) ;
164
+ /**
165
+ * Replace tab
166
+ *
167
+ * @param route Tab route
168
+ */
169
+ async function replaceTab ( key : RouteKey , options ?: App . Global . RouterPushOptions ) {
170
+ const oldTabId = activeTabId . value ;
171
+
172
+ // push new route
173
+ await routerPushByKey ( key , options ) ;
174
+
175
+ // remove old tab (exclude fixed tab)
176
+ if ( ! isTabRetain ( oldTabId ) ) {
177
+ await removeTab ( oldTabId ) ;
178
+ }
179
+ }
180
+
163
181
/**
164
182
* Switch route by tab
165
183
*
@@ -282,6 +300,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
282
300
removeTab,
283
301
removeActiveTab,
284
302
removeTabByRouteName,
303
+ replaceTab,
285
304
clearTabs,
286
305
clearLeftTabs,
287
306
clearRightTabs,
Original file line number Diff line number Diff line change @@ -175,6 +175,12 @@ declare namespace App {
175
175
type RoutePath = import ( '@elegant-router/types' ) . RoutePath ;
176
176
type LastLevelRouteKey = import ( '@elegant-router/types' ) . LastLevelRouteKey ;
177
177
178
+ /** The router push options */
179
+ type RouterPushOptions = {
180
+ query ?: Record < string , string > ;
181
+ params ?: Record < string , string > ;
182
+ } ;
183
+
178
184
/** The global header props */
179
185
interface HeaderProps {
180
186
/** Whether to show the logo */
You can’t perform that action at this time.
0 commit comments