router路由模式请参考下面demo:// Page1.ets import window from '@ohos.window'; @Entry @Component struct Page2 { @State message: string = 'page Page2'; onPageHide() { console.log("pageHide") } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button("pageB").onClick(() => { let windowStege: window.WindowStage = AppStorage.get("windowStage") as window.WindowStage; windowStege.createSubWindow("hello", (err, win) => { win.setUIContent('pages/Page2'); win.showWindow(); }) }) } .width('100%') } .height('100%') .backgroundColor(Color.Pink) } } // Page2.ets import window from '@ohos.window'; @Entry @Component struct Index { @State message: string = 'page Index'; aboutToAppear() { window.findWindow("hello").setWindowBackgroundColor("#00000000") } onBackPress() { window.findWindow("hello").destroyWindow().then((res) => { console.log("destroyWindow success") }).catch(() => { console.log("destroyWindow fail") }) return true } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') .backgroundColor(Color.Red) } .alignItems(VerticalAlign.Top) .height('100%') .backgroundColor("#80ffffff") } }注意需要在EntryAbility里面添加关键代码那一行onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Page231206095213071', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } AppStorage.setAndLink("windowStage", windowStage);// 关键代码 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); }支持 NavDestination支持Dialog类型页面:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navdestination-V5\#navdestinationmode枚举说明-11NavDestinationMode.STANDARD:标准类型NavDestination的生命周期NavDestinationMode.DIALOG:默认透明。
router路由模式请参考下面demo:
注意需要在EntryAbility里面添加关键代码那一行
支持 NavDestination支持Dialog类型页面:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navdestination-V5\#navdestinationmode枚举说明-11
NavDestinationMode.STANDARD:标准类型NavDestination的生命周期
NavDestinationMode.DIALOG:默认透明。