Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
NavDestination is the root container for Navigation subpages and is used to hold special attributes as well as lifecycles of subpages. You can set separate attributes such as the title bar and menu bar for NavDestination, in the same way you set attributes for Navigation. You can also set different display modes for NavDestination through the mode attribute to meet different page requirements.
NavDestination is divided into two modes:
Standard mode
By default, subpages in the NavDestination component are in standard mode, which corresponds to the NavDestinationMode.STANDARD value of the mode attribute. Only one standard NavDestination page can be displayed in Navigation.
Dialog mode
With mode set to NavDestinationMode.DIALOG, a NavDestination is displayed transparently by default. The appearance and disappearance of the NavDestination in dialog mode do not affect the display and lifecycle of the underlying NavDestination in standard mode, and both can be displayed at the same time.
- // Dialog NavDestination
- @Entry
- @Component
- struct PageDisplayType {
- @Provide('NavPathStack') pageStack: NavPathStack = new NavPathStack();
-
- @Builder
- PagesMap(name: string) {
- if (name == 'DialogPage') {
- DialogPage();
- }
- }
-
- build() {
- Navigation(this.pageStack) {
- Button('Push DialogPage')
- .margin(20)
- .width('80%')
- .onClick(() => {
- this.pageStack.pushPathByName('DialogPage', '');
- })
- }
- .mode(NavigationMode.Stack)
- .title('Main')
- .navDestination(this.PagesMap)
- }
- }
-
- @Component
- export struct DialogPage {
- @Consume('NavPathStack') pageStack: NavPathStack;
-
- build() {
- NavDestination() {
- Stack({ alignContent: Alignment.Center }) {
- Column() {
- Text('Dialog NavDestination')
- .fontSize(20)
- .margin({ bottom: 100 })
- Button('Close').onClick(() => {
- this.pageStack.pop();
- }).width('30%')
- }
- .justifyContent(FlexAlign.Center)
- .backgroundColor(Color.White)
- .borderRadius(10)
- .height('30%')
- .width('80%')
- }.height('100%').width('100%')
- }
- .backgroundColor('rgba(0,0,0,0.5)')
- .hideTitleBar(true)
- .mode(NavDestinationMode.DIALOG)
- }
- }

The lifecycle of Navigation can be divided into three categories: custom component lifecycle, universal component lifecycle, and NavDestination lifecycle. aboutToAppear and aboutToDisappear are the lifecycle callbacks of custom components (custom components contained in the outer layer of NavDestination); onAppear and onDisappear are universal component lifecycle callbacks. The remaining lifecycle events are unique to NavDestination.
The sequence of these lifecycle events is illustrated in the figure below.

In addition, there are two special lifecycle callbacks:
To facilitate the decoupling of components from pages, custom components within NavDestination subpages can listen for or query some page status information through global APIs.
Page information query
Custom components provide the queryNavDestinationInfo API, which can be used to query the information of the current page within NavDestination. The return value is NavDestinationInfo. If the query fails, the return value is undefined.
- import { uiObserver } from '@kit.ArkUI';
-
- // Custom components within NavDestination
- @Component
- struct MyComponent {
- navDesInfo: uiObserver.NavDestinationInfo | undefined;
- context = this.getUIContext().getHostContext();
-
- aboutToAppear() {
- this.navDesInfo = this.queryNavDestinationInfo();
- }
-
- build() {
- // ...
- Column() {
- // The value in the $r('app.string.onPageName') resource file is "Page name:".
- Text(this.context!.resourceManager.getStringSync($r('app.string.onPageName').id) + `${this.navDesInfo?.name}`)
- }.width('100%').height('100%')
- // ...
- }
- }
Page status listening
You can register a listener for NavDestination lifecycle changes using the observer.on('navDestinationUpdate') API.
Alternatively, you can register a callback for page transition states through observer.on('navDestinationSwitch'). This callback can be used to obtain page information during route changes using NavDestinationSwitchInfo. This registration supports different scopes: UIAbilityContext and UIContext.
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.