From 59223585000248bdb1c2fbefc24ede88084d45eb Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Fri, 19 Sep 2025 10:32:17 +0800 Subject: [PATCH 1/5] =?UTF-8?q?FAQ=EF=BC=9ANavigation=E9=80=9A=E8=BF=87pus?= =?UTF-8?q?hPathByName=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2=E4=B8=BA?= =?UTF-8?q?=E4=BB=80=E4=B9=88=E6=98=BE=E7=A4=BA=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/pages/NavigationDemo.ets | 71 +++++++++++++++++++ ArkUI/entry/src/main/module.json5 | 7 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 ArkUI/entry/src/main/ets/pages/NavigationDemo.ets diff --git a/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets new file mode 100644 index 0000000..4586589 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:Navigation通过pushPathByName跳转页面为什么显示空白 +*/ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Component +struct NavigationDemo { + pageStack: NavPathStack = new NavPathStack(); + + build() { + // [Start hideNavBar] + Navigation() { + // page content + // [StartExclude hideNavBar] + Button('pushPathByName') + .onClick(() => { + // [Start pushPathByName] + this.pageStack.pushPathByName('PageDetail', 'param'); + // [End pushPathByName] + }) + Button('pushPathByName') + .onClick(() => { + // [Start pushDestinationByName] + this.pageStack.pushDestinationByName('TargetPage', 'param') + .then(() => { + hilog.info(0x000, 'testTag', 'pushDestinationByName success'); + }) + .catch((error: BusinessError) => { + // Jump failed, redirected to custom page (such as Stay tuned page) + this.pageStack.pushPathByName('ErrorPage', 'param'); + hilog.error(0x000, 'testTag', `pushDestinationByName failed, code=${error.code}, message=${error.message}`); + }) + // [Start pushDestinationByName] + }) + // [EndExclude hideNavBar] + } + .hideNavBar(false) // Ensure not hidden + // [End hideNavBar] + } +} + +// [Start ChildPage] +// Subpage code, avoid creating it yourself +@Component +struct ChildPage { + // Error: Should not use new NavPathStack() + // pageStack: NavPathStack = new NavPathStack(); + // Correct: Inject the parent stack through @Consume or parameters + @Consume('pageStack') pageStack: NavPathStack; + build() { + // ... + } +} +// [End ChildPage] \ No newline at end of file diff --git a/ArkUI/entry/src/main/module.json5 b/ArkUI/entry/src/main/module.json5 index f610218..e653709 100644 --- a/ArkUI/entry/src/main/module.json5 +++ b/ArkUI/entry/src/main/module.json5 @@ -14,8 +14,11 @@ */ { + // [Start navigation_pushPathByName] "module": { "name": "entry", + // "type": "entry", // or shared, avoid using feature + // [StartExclude navigation_pushPathByName] "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -81,5 +84,7 @@ } ], // [End load_parent_temp] - } + // [EndExclude navigation_pushPathByName] + }, + // [End navigation_pushPathByName] } \ No newline at end of file -- Gitee From 62b20198e5383e2a523aadd1a77267b690cf55b2 Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Fri, 19 Sep 2025 10:36:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/pages/NavigationDemo.ets | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets index 4586589..2f591b7 100644 --- a/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets +++ b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets @@ -32,21 +32,22 @@ struct NavigationDemo { Button('pushPathByName') .onClick(() => { // [Start pushPathByName] + // Correct example: The name must match the routing table this.pageStack.pushPathByName('PageDetail', 'param'); // [End pushPathByName] }) - Button('pushPathByName') + Button('pushDestinationByName') .onClick(() => { // [Start pushDestinationByName] - this.pageStack.pushDestinationByName('TargetPage', 'param') - .then(() => { - hilog.info(0x000, 'testTag', 'pushDestinationByName success'); - }) - .catch((error: BusinessError) => { - // Jump failed, redirected to custom page (such as Stay tuned page) - this.pageStack.pushPathByName('ErrorPage', 'param'); - hilog.error(0x000, 'testTag', `pushDestinationByName failed, code=${error.code}, message=${error.message}`); - }) + this.pageStack.pushDestinationByName('TargetPage', 'param') + .then(() => { + hilog.info(0x000, 'testTag', 'pushDestinationByName success'); + }) + .catch((error: BusinessError) => { + // Jump failed, redirected to custom page (such as Stay tuned page) + this.pageStack.pushPathByName('ErrorPage', 'param'); + hilog.error(0x000, 'testTag', `pushDestinationByName failed, code=${error.code}, message=${error.message}`); + }) // [Start pushDestinationByName] }) // [EndExclude hideNavBar] -- Gitee From 8cc216f7ad8930971073120c795bb295634b6096 Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Fri, 19 Sep 2025 10:42:55 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArkUI/entry/src/main/ets/pages/NavigationDemo.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets index 2f591b7..db30f44 100644 --- a/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets +++ b/ArkUI/entry/src/main/ets/pages/NavigationDemo.ets @@ -39,6 +39,7 @@ struct NavigationDemo { Button('pushDestinationByName') .onClick(() => { // [Start pushDestinationByName] + // Asynchronous jump using pushDestructionByName this.pageStack.pushDestinationByName('TargetPage', 'param') .then(() => { hilog.info(0x000, 'testTag', 'pushDestinationByName success'); -- Gitee From 5c3acf1218653d409483997baa67428f3bc72eeb Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Fri, 19 Sep 2025 10:45:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9type=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArkUI/entry/src/main/module.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArkUI/entry/src/main/module.json5 b/ArkUI/entry/src/main/module.json5 index e653709..18e374c 100644 --- a/ArkUI/entry/src/main/module.json5 +++ b/ArkUI/entry/src/main/module.json5 @@ -17,7 +17,7 @@ // [Start navigation_pushPathByName] "module": { "name": "entry", - // "type": "entry", // or shared, avoid using feature + // "type": "har", // or shared, avoid using feature // [StartExclude navigation_pushPathByName] "type": "entry", "description": "$string:module_desc", -- Gitee From 6a071a3511147001677c019aefa2dca901037df5 Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Fri, 19 Sep 2025 10:47:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9name=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArkUI/entry/src/main/module.json5 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ArkUI/entry/src/main/module.json5 b/ArkUI/entry/src/main/module.json5 index 18e374c..b7aa93b 100644 --- a/ArkUI/entry/src/main/module.json5 +++ b/ArkUI/entry/src/main/module.json5 @@ -16,9 +16,10 @@ { // [Start navigation_pushPathByName] "module": { + // "name": "your_module", + // "type": "har", // or shared, avoid using feature, + // [StartExclude navigation_pushPathByName], "name": "entry", - // "type": "har", // or shared, avoid using feature - // [StartExclude navigation_pushPathByName] "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", -- Gitee