From 3ca9d51d4dc7f2f2a55b2925991ede96c5310096 Mon Sep 17 00:00:00 2001 From: Xc Date: Wed, 12 Nov 2025 12:56:28 +0800 Subject: [PATCH] =?UTF-8?q?navigator=E7=9A=84=E4=BB=A3=E7=A0=81=E6=9C=89?= =?UTF-8?q?=E8=BE=B9=E7=95=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/features/navigator.mp.js | 21 +++++++-------------- es/features/navigator.native.js | 13 ++++++++----- es/features/navigator.web.js | 6 +++--- lib/features/navigator.mp.js | 21 +++++++-------------- lib/features/navigator.native.js | 13 ++++++++----- lib/features/navigator.web.js | 6 +++--- lib/page.mp.js | 3 ++- src/features/navigator.mp.ts | 21 +++++++-------------- src/features/navigator.native.ts | 13 ++++++++----- src/features/navigator.web.ts | 6 +++--- 10 files changed, 56 insertions(+), 67 deletions(-) diff --git a/es/features/navigator.mp.js b/es/features/navigator.mp.js index 826751c6..a1a19204 100644 --- a/es/features/navigator.mp.js +++ b/es/features/navigator.mp.js @@ -75,13 +75,12 @@ export class Navigator extends CommonNavigator { wx.navigateTo({ url: url, success: () => { + this.leave(); this.publish(); resolve(undefined); }, fail: (err) => reject(err), }); - this.publish(); - this.leave(); }); } // 关闭当前页面,跳转到应用内的某个页面,但不允许跳转到tabBar页面。 @@ -94,12 +93,12 @@ export class Navigator extends CommonNavigator { wx.redirectTo({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } //跳转到tabBar页面,并关闭其他所有非tabBar页面,用于跳转到主页。 @@ -112,12 +111,12 @@ export class Navigator extends CommonNavigator { wx.switchTab({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } navigateBack(delta) { @@ -128,29 +127,23 @@ export class Navigator extends CommonNavigator { wx.navigateBack({ delta: delta || 1, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } navigateBackOrRedirectTo(options, state, disableNamespace) { - if (!this.enter()) { - return; - } const pages = getCurrentPages(); if (pages.length > 1) { - this.leave(); return this.navigateBack(); } const isTabBar = options?.isTabBar; if (isTabBar) { - this.leave(); return this.switchTab(options, state, disableNamespace); } - this.leave(); return this.redirectTo(options, state, disableNamespace); } } diff --git a/es/features/navigator.native.js b/es/features/navigator.native.js index 608fb551..404e61f6 100644 --- a/es/features/navigator.native.js +++ b/es/features/navigator.native.js @@ -56,8 +56,8 @@ export class Navigator extends CommonNavigator { const { url, props } = this.getUrlAndProps(options, state, disableNamespace); const replaceAction = StackActions.replace(url, props); this.history.dispatch(replaceAction); - this.publish(); this.leave(); + this.publish(); } async switchTab(options, state, disableNamespace) { if (!this.enter()) { @@ -66,8 +66,8 @@ export class Navigator extends CommonNavigator { const { url, props } = this.getUrlAndProps(options, state, disableNamespace); const jumpToAction = TabActions.jumpTo(url, props); this.history.dispatch(jumpToAction); - this.publish(); this.leave(); + this.publish(); } async navigateBack(delta) { if (!this.enter()) { @@ -77,9 +77,12 @@ export class Navigator extends CommonNavigator { if (canGoBack) { const popAction = StackActions.pop(delta || 1); this.history.dispatch(popAction); + this.leave(); this.publish(); } - this.leave(); + else { + this.leave(); + } } navigateBackOrRedirectTo(options, state, disableNamespace) { if (!this.enter()) { @@ -88,13 +91,13 @@ export class Navigator extends CommonNavigator { const canGoBack = this.history.canGoBack(); if (canGoBack) { this.navigateBack(); - this.publish(); this.leave(); + this.publish(); return; } // 回最顶层 this.history.dispatch(StackActions.popToTop()); - this.publish(); this.leave(); + this.publish(); } } diff --git a/es/features/navigator.web.js b/es/features/navigator.web.js index 6adfcf5f..dda05c33 100644 --- a/es/features/navigator.web.js +++ b/es/features/navigator.web.js @@ -45,8 +45,8 @@ export class Navigator extends CommonNavigator { } const { url, props } = this.getUrlAndProps(options, state, disableNamespace); this.history.push(url, props); - this.publish(); this.leave(); + this.publish(); } async redirectTo(options, state, disableNamespace) { if (!this.enter()) { @@ -54,8 +54,8 @@ export class Navigator extends CommonNavigator { } const { url, props } = this.getUrlAndProps(options, state, disableNamespace); this.history.replace(url, props); - this.publish(); this.leave(); + this.publish(); } async switchTab(options, state, disableNamespace) { console.error('浏览器无switchTab'); @@ -68,8 +68,8 @@ export class Navigator extends CommonNavigator { return; } this.history.go(delta ? 0 - delta : -1); - this.publish(); this.leave(); + this.publish(); } navigateBackOrRedirectTo(options, state, disableNamespace) { console.error('浏览器暂无法获得history堆栈'); diff --git a/lib/features/navigator.mp.js b/lib/features/navigator.mp.js index 9b5f35ba..d346c295 100644 --- a/lib/features/navigator.mp.js +++ b/lib/features/navigator.mp.js @@ -78,13 +78,12 @@ class Navigator extends navigator_common_1.Navigator { wx.navigateTo({ url: url, success: () => { + this.leave(); this.publish(); resolve(undefined); }, fail: (err) => reject(err), }); - this.publish(); - this.leave(); }); } // 关闭当前页面,跳转到应用内的某个页面,但不允许跳转到tabBar页面。 @@ -97,12 +96,12 @@ class Navigator extends navigator_common_1.Navigator { wx.redirectTo({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } //跳转到tabBar页面,并关闭其他所有非tabBar页面,用于跳转到主页。 @@ -115,12 +114,12 @@ class Navigator extends navigator_common_1.Navigator { wx.switchTab({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } navigateBack(delta) { @@ -131,29 +130,23 @@ class Navigator extends navigator_common_1.Navigator { wx.navigateBack({ delta: delta || 1, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } navigateBackOrRedirectTo(options, state, disableNamespace) { - if (!this.enter()) { - return; - } const pages = getCurrentPages(); if (pages.length > 1) { - this.leave(); return this.navigateBack(); } const isTabBar = options?.isTabBar; if (isTabBar) { - this.leave(); return this.switchTab(options, state, disableNamespace); } - this.leave(); return this.redirectTo(options, state, disableNamespace); } } diff --git a/lib/features/navigator.native.js b/lib/features/navigator.native.js index d5558061..538752b1 100644 --- a/lib/features/navigator.native.js +++ b/lib/features/navigator.native.js @@ -59,8 +59,8 @@ class Navigator extends navigator_common_1.Navigator { const { url, props } = this.getUrlAndProps(options, state, disableNamespace); const replaceAction = native_1.StackActions.replace(url, props); this.history.dispatch(replaceAction); - this.publish(); this.leave(); + this.publish(); } async switchTab(options, state, disableNamespace) { if (!this.enter()) { @@ -69,8 +69,8 @@ class Navigator extends navigator_common_1.Navigator { const { url, props } = this.getUrlAndProps(options, state, disableNamespace); const jumpToAction = native_1.TabActions.jumpTo(url, props); this.history.dispatch(jumpToAction); - this.publish(); this.leave(); + this.publish(); } async navigateBack(delta) { if (!this.enter()) { @@ -80,9 +80,12 @@ class Navigator extends navigator_common_1.Navigator { if (canGoBack) { const popAction = native_1.StackActions.pop(delta || 1); this.history.dispatch(popAction); + this.leave(); this.publish(); } - this.leave(); + else { + this.leave(); + } } navigateBackOrRedirectTo(options, state, disableNamespace) { if (!this.enter()) { @@ -91,14 +94,14 @@ class Navigator extends navigator_common_1.Navigator { const canGoBack = this.history.canGoBack(); if (canGoBack) { this.navigateBack(); - this.publish(); this.leave(); + this.publish(); return; } // 回最顶层 this.history.dispatch(native_1.StackActions.popToTop()); - this.publish(); this.leave(); + this.publish(); } } exports.Navigator = Navigator; diff --git a/lib/features/navigator.web.js b/lib/features/navigator.web.js index e41ee72a..d442c17f 100644 --- a/lib/features/navigator.web.js +++ b/lib/features/navigator.web.js @@ -48,8 +48,8 @@ class Navigator extends navigator_common_1.Navigator { } const { url, props } = this.getUrlAndProps(options, state, disableNamespace); this.history.push(url, props); - this.publish(); this.leave(); + this.publish(); } async redirectTo(options, state, disableNamespace) { if (!this.enter()) { @@ -57,8 +57,8 @@ class Navigator extends navigator_common_1.Navigator { } const { url, props } = this.getUrlAndProps(options, state, disableNamespace); this.history.replace(url, props); - this.publish(); this.leave(); + this.publish(); } async switchTab(options, state, disableNamespace) { console.error('浏览器无switchTab'); @@ -71,8 +71,8 @@ class Navigator extends navigator_common_1.Navigator { return; } this.history.go(delta ? 0 - delta : -1); - this.publish(); this.leave(); + this.publish(); } navigateBackOrRedirectTo(options, state, disableNamespace) { console.error('浏览器暂无法获得history堆栈'); diff --git a/lib/page.mp.js b/lib/page.mp.js index b905b135..e96cdd2d 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.createComponent = createComponent; +exports.createComponent = void 0; /// const assert_1 = require("oak-domain/lib/utils/assert"); const types_1 = require("oak-domain/lib/types"); @@ -886,3 +886,4 @@ function createComponent(option, features) { }, }); } +exports.createComponent = createComponent; diff --git a/src/features/navigator.mp.ts b/src/features/navigator.mp.ts index 4dbc2bfb..85e7ea36 100644 --- a/src/features/navigator.mp.ts +++ b/src/features/navigator.mp.ts @@ -108,13 +108,12 @@ export class Navigator extends CommonNavigator { wx.navigateTo({ url: url, success: () => { + this.leave(); this.publish(); resolve(undefined); }, fail: (err) => reject(err), }); - this.publish(); - this.leave(); }); } @@ -133,12 +132,12 @@ export class Navigator extends CommonNavigator { wx.redirectTo({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } @@ -156,12 +155,12 @@ export class Navigator extends CommonNavigator { wx.switchTab({ url: url, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } @@ -173,12 +172,12 @@ export class Navigator extends CommonNavigator { wx.navigateBack({ delta: delta || 1, success: () => { - resolve(undefined); + this.leave(); this.publish(); + resolve(undefined); }, fail: (err) => reject(err), }); - this.leave(); }); } @@ -193,20 +192,14 @@ export class Navigator extends CommonNavigator { state?: Record, disableNamespace?: boolean ) { - if (!this.enter()) { - return; - } const pages = getCurrentPages(); if (pages.length > 1) { - this.leave(); return this.navigateBack(); } const isTabBar = options?.isTabBar; if (isTabBar) { - this.leave(); return this.switchTab(options, state, disableNamespace); } - this.leave(); return this.redirectTo(options, state, disableNamespace); } } diff --git a/src/features/navigator.native.ts b/src/features/navigator.native.ts index 7d909603..c3a1579a 100644 --- a/src/features/navigator.native.ts +++ b/src/features/navigator.native.ts @@ -109,8 +109,8 @@ export class Navigator extends CommonNavigator { ); const replaceAction = StackActions.replace(url, props); this.history.dispatch(replaceAction); - this.publish(); this.leave(); + this.publish(); } async switchTab< @@ -131,8 +131,8 @@ export class Navigator extends CommonNavigator { ); const jumpToAction = TabActions.jumpTo(url, props); this.history.dispatch(jumpToAction); - this.publish(); this.leave(); + this.publish(); } async navigateBack(delta?: number) { @@ -143,9 +143,12 @@ export class Navigator extends CommonNavigator { if (canGoBack) { const popAction = StackActions.pop(delta || 1); this.history.dispatch(popAction); + this.leave(); this.publish(); } - this.leave(); + else { + this.leave(); + } } navigateBackOrRedirectTo< @@ -165,13 +168,13 @@ export class Navigator extends CommonNavigator { const canGoBack = this.history.canGoBack(); if (canGoBack) { this.navigateBack(); - this.publish(); this.leave(); + this.publish(); return; } // 回最顶层 this.history.dispatch(StackActions.popToTop()); - this.publish(); this.leave(); + this.publish(); } } diff --git a/src/features/navigator.web.ts b/src/features/navigator.web.ts index b390fba5..1595b731 100644 --- a/src/features/navigator.web.ts +++ b/src/features/navigator.web.ts @@ -82,8 +82,8 @@ export class Navigator extends CommonNavigator { disableNamespace ); this.history.push(url, props); - this.publish(); this.leave(); + this.publish(); } async redirectTo< @@ -103,8 +103,8 @@ export class Navigator extends CommonNavigator { disableNamespace ); this.history.replace(url, props); - this.publish(); this.leave(); + this.publish(); } async switchTab< @@ -130,8 +130,8 @@ export class Navigator extends CommonNavigator { return; } this.history.go(delta ? 0 - delta : -1); - this.publish(); this.leave(); + this.publish(); } navigateBackOrRedirectTo<