File tree 3 files changed +28
-7
lines changed
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) {
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,25 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
160
160
update ( ) ;
161
161
}
162
162
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
+
163
182
/**
164
183
* Switch route by tab
165
184
*
@@ -282,6 +301,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
282
301
removeTab,
283
302
removeActiveTab,
284
303
removeTabByRouteName,
304
+ replaceTab,
285
305
clearTabs,
286
306
clearLeftTabs,
287
307
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