1e41f4b71Sopenharmony_ci# Navigation 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **Navigation** component is the root view container for navigation. It typically functions as the root container of a page and includes a title bar, content area, and toolbar. The content area switches between the home page content (child components of **Navigation**) and non-home page content (child components of [NavDestination](ts-basic-components-navdestination.md)) through routing. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> Since API version 11, this component supports the safe area attribute by default, with the default attribute value being **expandSafeArea([SafeAreaType.SYSTEM, SafeAreaType.KEYBOARD, SafeAreaType.CUTOUT], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])**. You can override this attribute to change the default behavior. In earlier versions, you need to use the [expandSafeArea](ts-universal-attributes-expand-safe-area.md) attribute to implement the safe area feature. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Child Components 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciSupported 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciSince API version 9, it is recommended that this component be used together with the [NavRouter](ts-basic-components-navrouter.md) component. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciSince API version 10, it is recommended that this component be used together with the [NavPathStack](#navpathstack10) component and **navDestination** attribute for page routing. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## APIs 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci### Navigation 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciNavigation() 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci### Navigation<sup>10+</sup> 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciNavigation(pathInfos: NavPathStack) 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciBinds a navigation stack to the **Navigation** component. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Parameters** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 43e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- | ------ | 44e41f4b71Sopenharmony_ci| pathInfos | [NavPathStack](#navpathstack10) | No | Information about the navigation stack.| 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci## Attributes 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci### title 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_cititle(value: ResourceStr | CustomBuilder | NavigationCommonTitle | NavigationCustomTitle, options?: NavigationTitleOptions) 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciSets the page title. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**Parameters** 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 63e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 64e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr)<sup>10+</sup> \| [CustomBuilder](ts-types.md#custombuilder8) \| [NavigationCommonTitle](#navigationcommontitle9)<sup>9+</sup> \| [NavigationCustomTitle](#navigationcustomtitle9)<sup>9+</sup> | Yes | Page title. When the NavigationCustomTitle type is used to set the height, [titleMode](#titlemode) does not take effect. When the title string is too long: (1) If no subtitle is set, the string is scaled down, wrapped in two lines, and then clipped with an ellipsis (...); (2) If a subtitle is set, the subtitle is scaled down and then clipped with an ellipsis (...).| 65e41f4b71Sopenharmony_ci| options | [NavigationTitleOptions](#navigationtitleoptions11)<sup>11+</sup> | No | Title bar options. | 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci### subTitle<sup>(deprecated)</sup> 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_cisubTitle(value: string) 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciSets the page subtitle. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciThis API is deprecated since API version 9. You are advised to use [title](#title) instead. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**Parameters** 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 80e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ | 81e41f4b71Sopenharmony_ci| value | string | Yes | Page subtitle.| 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci### menus 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_cimenus(value: Array<NavigationMenuItem> | CustomBuilder) 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci> **NOTE** 88e41f4b71Sopenharmony_ci> 89e41f4b71Sopenharmony_ci> The following are not allowed: modify the icon size through the **fontSize** attribute of the **SymbolGlyphModifier** object, change the animation effects through the **effectStrategy** attribute, or change the type of animation effects through the **symbolEffect** attribute. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ciSets the menu items in the upper right corner of the page. If this attribute is not set, no menu item is displayed. When the value type is Array<[NavigationMenuItem](#navigationmenuitem)>, the menu shows a maximum of three icons in portrait mode and a maximum of five icons in landscape mode, with excess icons (if any) placed under the automatically generated **More** icon. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**Parameters** 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 101e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ---------------- | 102e41f4b71Sopenharmony_ci| value | Array<[NavigationMenuItem](#navigationmenuitem)> \| [CustomBuilder](ts-types.md#custombuilder8) | Yes | Menu items in the upper right corner of the page.| 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci### titleMode 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_cititleMode(value: NavigationTitleMode) 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ciSets the display mode of the page title bar. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**Parameters** 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 117e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------- | ---- | --------------------------------------------------------- | 118e41f4b71Sopenharmony_ci| value | [NavigationTitleMode](#navigationtitlemode) | Yes | Display mode of the page title bar.<br>Default value: **NavigationTitleMode.Free**| 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci### toolBar<sup>(deprecated)</sup> 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_citoolBar(value: object | CustomBuilder) 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ciSets the content of the toolbar. If this attribute is not set, no toolbar is displayed. Items are evenly distributed on the toolbar at the bottom. Text and icons are evenly distributed in each content area. If the text is too long, it is scaled down level by level, wrapped in two lines, and then clipped with an ellipsis (...). 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ciThis API is deprecated since API version 10. You are advised to use [toolbarConfiguration](#toolbarconfiguration10) instead. 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**Parameters** 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 133e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------ | 134e41f4b71Sopenharmony_ci| value | object \| [CustomBuilder](ts-types.md#custombuilder8) | Yes | Content of the toolbar.| 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci**object** 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 139e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | --------------- | 140e41f4b71Sopenharmony_ci| value | string | Yes | Text of the toolbar item. | 141e41f4b71Sopenharmony_ci| icon | string | No | Icon path of the toolbar item.| 142e41f4b71Sopenharmony_ci| action | () => void | No | Callback invoked when the menu item is selected. | 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci### toolbarConfiguration<sup>10+</sup> 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_citoolbarConfiguration(value: Array<ToolbarItem> | CustomBuilder, options?: NavigationToolbarOptions) 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci> **NOTE** 149e41f4b71Sopenharmony_ci> 150e41f4b71Sopenharmony_ci> The following are not allowed: modify the icon size through the **fontSize** attribute of the **SymbolGlyphModifier** object, change the animation effects through the **effectStrategy** attribute, or change the type of animation effects through the **symbolEffect** attribute. 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ciSets the content of the toolbar. If this attribute is not set, no toolbar is displayed. 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Widget capability**: Since API version 10, this API is supported in ArkTS widgets. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**Parameters** 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 164e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 165e41f4b71Sopenharmony_ci| value | Array<[ToolbarItem](#toolbaritem10)> \| [CustomBuilder](ts-types.md#custombuilder8) | Yes | Content of the toolbar. When the value type is Array<[ToolbarItem](#toolbaritem10), the toolbar exhibits the following features:<br>Items are evenly distributed on the toolbar at the bottom. Text and icons are evenly distributed in each content area.<br>If any item contains overlong text and there are fewer than five items, the following measures are taken: 1. Increase the item's width to accommodate the text until it is as large as the screen width; 2. Scale down the text level by level; 3. Wrap the text in two lines; 4. Clip the text with an ellipsis (...).<br>The toolbar shows a maximum of five icons in portrait mode, with excess icons (if any) placed under the automatically generated **More** icon. In landscape mode, this attribute must be used together with Array<[NavigationMenuItem](#navigationmenuitem)> of the **menus** attribute; the toolbar at the bottom is automatically hidden, and all items on the toolbar are moved to the menu in the upper right corner of the screen.<br>When the value type is [CustomBuilder](ts-types.md#custombuilder8), and the toolbar does not exhibit the preceding features except that items are evenly distributed on the toolbar at the bottom.| 166e41f4b71Sopenharmony_ci| options | [NavigationToolbarOptions](#navigationtoolbaroptions11)<sup>11+</sup> | No | Toolbar options. | 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci### hideToolBar 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_cihideToolBar(value: boolean) 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ciSpecifies whether to hide the toolbar. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**Parameters** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 181e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 182e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the toolbar.<br>Default value: **false**<br>**true**: Hide the toolbar.<br>**false**: Show the toolbar.| 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci### hideTitleBar 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_cihideTitleBar(value: boolean) 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ciSpecifies whether to hide the title bar. 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**Parameters** 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 197e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 198e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the title bar.<br>Default value: **false**<br>**true**: Hide the title bar.<br>**false**: Show the title bar.| 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci### hideBackButton 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_cihideBackButton(value: boolean) 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ciSpecifies whether to hide the back button in the title bar. The back button is available only when [titleMode](#titlemode) is set to **NavigationTitleMode.Mini**. 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**Parameters** 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 213e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 214e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the back button in the title bar.<br>Default value: **false**<br>**true**: Hide the back button.<br>**false**: Show the back button.| 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci### navBarWidth<sup>9+</sup> 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_cinavBarWidth(value: Length) 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ciSets the width of the navigation bar. This attribute takes effect only when the **Navigation** component is split. 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**Parameters** 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 229e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ----------------------------------------- | 230e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | Yes | Width of the navigation bar.<br>Default value: **240**<br>Unit: vp<br>**undefined**: No action is taken, and the navigation bar width remains consistent with the default value.| 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci### navBarPosition<sup>9+</sup> 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_cinavBarPosition(value: NavBarPosition) 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ciSets the position of the navigation bar. This attribute takes effect only when the **Navigation** component is split. 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**Parameters** 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 245e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | --------------------------------------------- | 246e41f4b71Sopenharmony_ci| value | [NavBarPosition](#navbarposition9) | Yes | Position of the navigation bar.<br>Default value: **NavBarPosition.Start**| 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci### mode<sup>9+</sup> 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_cimode(value: NavigationMode) 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciSets the display mode of the navigation bar. Available options are **Stack**, **Split**, and **Auto**. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**Parameters** 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 261e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 262e41f4b71Sopenharmony_ci| value | [NavigationMode](#navigationmode9) | Yes | Display mode of the navigation bar.<br>Default value: **NavigationMode.Auto**<br>At the default settings, the component adapts to a single column or two columns based on the component width.| 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci### backButtonIcon<sup>9+</sup> 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_cibackButtonIcon(value: string | PixelMap | Resource | SymbolGlyphModifier) 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci> **NOTE** 269e41f4b71Sopenharmony_ci> 270e41f4b71Sopenharmony_ci> The following are not allowed: modify the icon size through the **fontSize** attribute of the **SymbolGlyphModifier** object, change the animation effects through the **effectStrategy** attribute, or change the type of animation effects through the **symbolEffect** attribute. 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ciSets the icon of the back button in the title bar. 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**Parameters** 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 282e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------- | 283e41f4b71Sopenharmony_ci| value | string \| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) \| [Resource](ts-types.md#resource) \| [SymbolGlyphModifier<sup>12+</sup>](ts-universal-attributes-attribute-modifier.md) | Yes | Icon of the back button in the title bar.| 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci### hideNavBar<sup>9+</sup> 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_cihideNavBar(value: boolean) 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ciSpecifies whether to hide the navigation bar. If this parameter is set to **true**, the navigation bar, including the title bar, content area, and toolbar, is hidden. In this case, if the navigation destination page is in the navigation stack, it is moved to the top of the stack and displayed. Otherwise, a blank page is displayed. 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ciFrom API version 9 to API version 10, this attribute takes effect only in dual-column mode. Since API version 11, this attribute takes effect in single-column, dual-column, and auto modes. 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci**Parameters** 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 300e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- | 301e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to hide the navigation bar.<br>Default value: **false**| 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci### navDestination<sup>10+</sup> 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_cinavDestination(builder: (name: string, param: unknown) => void) 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ciBuilder for a **NavDestination** component. The **builder** function is used, with the **name** and **param** parameters passed in. The **builder** can have only one root node. In the builder, a layer of custom components can be included outside the **NavDestination** component. However, no attributes or events can be set for the custom components. Otherwise, only blank components are displayed. 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci**Parameters** 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 316e41f4b71Sopenharmony_ci| ------- | -------------------------------------- | ---- | ------------------------ | 317e41f4b71Sopenharmony_ci| builder | (name: string, param: unknown) => void | Yes | Builder for a **NavDestination** component.| 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci### navBarWidthRange<sup>10+</sup> 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_cinavBarWidthRange(value: [Dimension, Dimension]) 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ciSets the minimum and maximum widths of the navigation bar (effective in dual-column mode). 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ciFor details about the priority rules, see **NOTE** below. 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci**Parameters** 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 334e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 335e41f4b71Sopenharmony_ci| value | [[Dimension](ts-types.md#dimension10), [Dimension](ts-types.md#dimension10)] | Yes | Minimum and maximum widths of the navigation bar.<br>Default value: 240 for the minimum value; 40% of the component width (not greater than 432) for the maximum value; if either of the widths is not set, the default value is used for that width.<br>Unit: vp| 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci### minContentWidth<sup>10+</sup> 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ciminContentWidth(value: Dimension) 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciSets the minimum width of the navigation bar content area (effective in dual-column mode). 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ciFor details about the priority rules, see **NOTE** below. 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**Parameters** 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 352e41f4b71Sopenharmony_ci| ------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 353e41f4b71Sopenharmony_ci| value | [Dimension](ts-types.md#dimension10) | Yes | Minimum width of the navigation bar content area.<br>Default value: **360**<br>Unit: vp<br>**undefined**: No action is taken, and the minimum width of the navigation bar remains consistent with the default value.<br>Breakpoint calculation in Auto mode: default 600 vp = minNavBarWidth (240 vp) + minContentWidth (360 vp)| 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci> **NOTE** 356e41f4b71Sopenharmony_ci> 357e41f4b71Sopenharmony_ci> 1. If only **navBarWidth** is set, no divider in the **Navigation** component can be dragged. 358e41f4b71Sopenharmony_ci> 359e41f4b71Sopenharmony_ci> 2. **navBarWidthRange** specifies the range within which the divider can be dragged. If it is not set, the default value is used. The dragging of the divider is subject to both **navBarWidthRange** and **minContentWidth**. 360e41f4b71Sopenharmony_ci> 361e41f4b71Sopenharmony_ci> 3. If the size of the **Navigation** component decreases, it carries out the following steps in sequence:<br>a. Scale down the content area. If **minContentWidth** is not set, the content area can be scaled down to 0. Otherwise, the content area can be scaled down to as small as the value specified by **minContentWidth**.b. Scale down the navigation bar until its width reaches the value defined by **navBarRange**.c. Clip the displayed content. 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci### ignoreLayoutSafeArea<sup>12+</sup> 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ciignoreLayoutSafeArea(types?: Array<LayoutSafeAreaType>, edges?: Array<LayoutSafeAreaEdge>) 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ciIgnores the layout safe area by allowing the component to extend into the non-safe areas of the screen. 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**Parameters** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 376e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 377e41f4b71Sopenharmony_ci| types | Array <[LayoutSafeAreaType](ts-types.md#layoutsafeareatype12)> | No | Types of non-safe areas to extend into.<br>Default value:<br>[LayoutSafeAreaType.SYSTEM] | 378e41f4b71Sopenharmony_ci| edges | Array <[LayoutSafeAreaEdge](ts-types.md#layoutsafeareaedge12)> | No | Edges for expanding the safe area.<br> Default value:<br>[LayoutSafeAreaEdge.TOP, LayoutSafeAreaEdge.BOTTOM]| 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci> **NOTE** 381e41f4b71Sopenharmony_ci> 382e41f4b71Sopenharmony_ci> After **LayoutSafeArea** is set: 383e41f4b71Sopenharmony_ci> When **LayoutSafeAreaType.SYSTEM** is set, the component can extend into the non-safe area if its boundaries overlap with it. For example, if the device's status bar is 100 high, the component must have an absolute vertical offset between 0 and 100 to extend into the non-safe area. 384e41f4b71Sopenharmony_ci> 385e41f4b71Sopenharmony_ci> If the component extends into the non-safe area, events triggered within that area (such as click events) might be intercepted by the system. This allows the system to prioritize responses to system components such as the status bar. 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci### systemBarStyle<sup>12+</sup> 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_cisystemBarStyle(style: Optional<SystemBarStyle>) 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ciSets the style of the system status bar when the home page of the **Navigation** component is displayed. 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci**Parameters** 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 400e41f4b71Sopenharmony_ci| ------ | -------------- | ---- | ------------------ | 401e41f4b71Sopenharmony_ci| style | Optional<[SystemBarStyle](../js-apis-window.md#systembarstyle12)> | Yes | Style of the system status bar.| 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci> **Instructions** 404e41f4b71Sopenharmony_ci> 405e41f4b71Sopenharmony_ci> 1. Avoid using the **systemBarStyle** attribute in conjunction with the status bar style APIs in the **Window** module, such as [setWindowSystemBarProperties](../js-apis-window.md#setwindowsystembarproperties9). 406e41f4b71Sopenharmony_ci> 2. When you first set the **systemBarStyle** attribute for a **Navigation** or **NavDestination** component, the current status bar style is saved for potential future restoration. 407e41f4b71Sopenharmony_ci> 3. The status bar style is determined by the home page of the **Navigation** component (if there are no **NavDestination** pages on the navigation stack) or the top **NavDestination** page on the navigation stack. 408e41f4b71Sopenharmony_ci> 4. If the home page or any top **NavDestination** page has a valid **systemBarStyle** set, that style will be used. If no style is set, and there is a previously saved style available, the saved style will be used. If no style has been set or saved, no changes will be made. 409e41f4b71Sopenharmony_ci> 5. In [Split](#navigationmode9) mode, if there is no **NavDestination** in the content area, the settings of the **Navigation** home page will apply. Otherwise, the settings of the top **NavDestination** page on the navigation stack will apply. 410e41f4b71Sopenharmony_ci> 6. The **systemBarStyle** attribute is effective only for the main page of the main window. 411e41f4b71Sopenharmony_ci> 7. The set style will only take effect if the **Navigation** component spans the entire page. If it does not, and there is a previously saved style available, the saved style will be used instead. 412e41f4b71Sopenharmony_ci> 8. When different styles are set for pages, the new style takes effect at the start of the page transition. 413e41f4b71Sopenharmony_ci> 9. The status bar style set by **Navigation** or **NavDestination** does not apply in non-fullscreen windows. 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci## Events 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci### onTitleModeChange 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_cionTitleModeChange(callback: (titleMode: NavigationTitleMode) => void) 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ciCalled when [titleMode](#titlemode) is set to **NavigationTitleMode.Free** and the title bar mode changes as content scrolls. 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci**Parameters** 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 430e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------- | ---- | ---------- | 431e41f4b71Sopenharmony_ci| titleMode | [NavigationTitleMode](#navigationtitlemode) | Yes | Title mode.| 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci### onNavBarStateChange<sup>9+</sup> 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_cionNavBarStateChange(callback: (isVisible: boolean) => void) 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ciCalled when the navigation bar visibility status changes. 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci**Parameters** 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 446e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ---------------------------------------------- | 447e41f4b71Sopenharmony_ci| isVisible | boolean | Yes | Whether the navigation bar is visible. The value **true** means that the navigation bar is visible, and **false** means the opposite.| 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci### onNavigationModeChange<sup>11+</sup> 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_cionNavigationModeChange(callback: (mode: NavigationMode) => void) 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ciCalled when the **Navigation** component is displayed for the first time or its display mode switches between single-column and dual-column. 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**Parameters** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 462e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ---------------------------------------------- | 463e41f4b71Sopenharmony_ci| mode | [NavigationMode](#navigationmode9) | Yes | **NavigationMode.Split**: The component is displayed in two columns.<br>**NavigationMode.Stack**: The component is displayed in a single column.| 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci### customNavContentTransition<sup>11+</sup> 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_cicustomNavContentTransition(delegate(from: NavContentInfo, to: NavContentInfo, operation: NavigationOperation) => NavigationAnimatedTransition | undefined) 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ciCallback of the custom transition animation. 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**Parameters** 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 478e41f4b71Sopenharmony_ci| --------- | ----------------------------------------------------- | ---- | ----------------------- | 479e41f4b71Sopenharmony_ci| from | [NavContentInfo](#navcontentinfo11) | Yes | Destination page to exit.| 480e41f4b71Sopenharmony_ci| to | [NavContentInfo](#navcontentinfo11) | Yes | Destination page to enter.| 481e41f4b71Sopenharmony_ci| operation | [NavigationOperation](#navigationoperation11) | Yes | Transition type. | 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci**Return value** 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| Type | Description | 486e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 487e41f4b71Sopenharmony_ci| [NavigationAnimatedTransition](#navigationanimatedtransition11) \| undefined | Custom transition animation agreement.<br>**undefined**: The default transition effect is executed.| 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci## NavPathStack<sup>10+</sup> 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ciImplements a navigation stack, which allows for inheritance since API version 12. You can add new properties and methods in derived classes, or you can override the methods of the base **NavPathStack** class. Objects of the derived class can be used in place of objects of the base **NavPathStack** class. For details, see [Example](#example-10). 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci### pushPath<sup>10+</sup> 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_cipushPath(info: NavPathInfo, animated?: boolean): void 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **info** to the navigation stack. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**Parameters** 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 506e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 507e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Information about the navigation destination page.| 508e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci### pushPath<sup>12+</sup> 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_cipushPath(info: NavPathInfo, options?: NavigationOptions): void 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **info** onto the navigation stack. Depending on the [LaunchMode](#launchmode12) specified in the **options** parameter, different behaviors will be triggered. 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci**Parameters** 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 523e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 524e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Information about the navigation destination page.| 525e41f4b71Sopenharmony_ci| options | [NavigationOptions](#navigationoptions12) | No | Navigation options.| 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci### pushPathByName<sup>10+</sup> 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_cipushPathByName(name: string, param: unknown, animated?: boolean): void 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **name**, with the data specified by **param**, to the navigation stack. 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci**Parameters** 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 540e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 541e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 542e41f4b71Sopenharmony_ci| param | unknown | Yes | Detailed parameters of the navigation destination page.| 543e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci### pushPathByName<sup>11+</sup> 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_cipushPathByName(name: string, param: Object, onPop: Callback\<PopInfo>, animated?: boolean): void 548e41f4b71Sopenharmony_ci 549e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **name**, with the data specified by **param**, to the navigation stack. This API uses the **onPop** callback to receive the result returned when the page is popped out of the stack. 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci**Parameters** 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 558e41f4b71Sopenharmony_ci|------|------|------|------| 559e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 560e41f4b71Sopenharmony_ci| param | Object | Yes | Detailed parameters of the navigation destination page.| 561e41f4b71Sopenharmony_ci| onPop | Callback\<[PopInfo](#popinfo11)> | Yes| Callback used to receive the result. It is invoked only after the **result** parameter is set in **pop**.| 562e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci### pushDestination<sup>11+</sup> 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_cipushDestination(info: NavPathInfo, animated?: boolean): Promise<void> 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **info** to the navigation stack. This API uses a promise to return the result. 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**Parameters** 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 577e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 578e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Information about the navigation destination page.| 579e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**Return value** 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci| Type | Description | 584e41f4b71Sopenharmony_ci| ------------------- | --------- | 585e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**Error codes** 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../../errorcode-universal.md) and [Router Error Codes](../errorcode-router.md). 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci| ID | Error Message| 592e41f4b71Sopenharmony_ci| --------- | ------- | 593e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 594e41f4b71Sopenharmony_ci| 100001 | Internal error.| 595e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 596e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci### pushDestination<sup>12+</sup> 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_cipushDestination(info: NavPathInfo, options?: NavigationOptions): Promise<void> 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **info** onto the navigation stack. This API uses a promise to return the result. Depending on the [LaunchMode](#launchmode12) specified in the **options** parameter, different behaviors will be triggered. 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci**Parameters** 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 611e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 612e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Information about the navigation destination page.| 613e41f4b71Sopenharmony_ci| options | [NavigationOptions](#navigationoptions12) | No | Navigation options.| 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**Return value** 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci| Type | Description | 618e41f4b71Sopenharmony_ci| ------------------- | --------- | 619e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**Error codes** 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../../errorcode-universal.md) and [Router Error Codes](../errorcode-router.md). 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci| ID | Error Message| 626e41f4b71Sopenharmony_ci| --------- | ------- | 627e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 628e41f4b71Sopenharmony_ci| 100001 | Internal error.| 629e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 630e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci### pushDestinationByName<sup>11+</sup> 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_cipushDestinationByName(name: string, param: Object, animated?: boolean): Promise<void> 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **name**, with the data specified by **param**, to the navigation stack. This API uses a promise to return the result. 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci**Parameters** 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 645e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 646e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 647e41f4b71Sopenharmony_ci| param | Object | Yes | Detailed parameters of the navigation destination page.| 648e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**Return value** 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci| Type | Description | 653e41f4b71Sopenharmony_ci| ------------------- | --------- | 654e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**Error codes** 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../../errorcode-universal.md) and [Router Error Codes](../errorcode-router.md). 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci| ID | Error Message| 661e41f4b71Sopenharmony_ci| --------- | ------- | 662e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 663e41f4b71Sopenharmony_ci| 100001 | Internal error.| 664e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 665e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci### pushDestinationByName<sup>11+</sup> 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_cipushDestinationByName(name: string, param: Object, onPop: Callback\<PopInfo>, animated?: boolean): Promise<void> 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ciPushes the navigation destination page specified by **name**, with the data specified by **param**, to the navigation stack. This API uses the **onPop** callback to handle the result returned when the page is popped out of the stack. It uses a promise to return the result. 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci**Parameters** 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 680e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 681e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 682e41f4b71Sopenharmony_ci| param | Object | Yes | Detailed parameters of the navigation destination page.| 683e41f4b71Sopenharmony_ci| onPop | Callback\<[PopInfo](#popinfo11)> | Yes | Callback used to handle the result returned when the page is popped out of the stack. It is invoked only after the **result** parameter is set in **pop**.| 684e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci**Return value** 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci| Type | Description | 689e41f4b71Sopenharmony_ci| ------------------- | --------- | 690e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the result.| 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ci**Error codes** 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../../errorcode-universal.md) and [Router Error Codes](../errorcode-router.md). 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci| ID | Error Message| 697e41f4b71Sopenharmony_ci| --------- | ------- | 698e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 699e41f4b71Sopenharmony_ci| 100001 | Internal error.| 700e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 701e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci### replacePath<sup>11+</sup> 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_cireplacePath(info: NavPathInfo, animated?: boolean): void 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ciReplaces the top of the navigation stack with the page specified by **info**. 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**Parameters** 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 716e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 717e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Parameters of the page to replace the top of the navigation stack.| 718e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci### replacePath<sup>12+</sup> 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_cireplacePath(info: NavPathInfo, options?: NavigationOptions): void 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ciReplaces the top page on the navigation stack. Depending on the [LaunchMode](#launchmode12) specified in the **options** parameter, different behaviors will be triggered. 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci**Parameters** 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 733e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 734e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes | Parameters for the new top page of the navigation stack.| 735e41f4b71Sopenharmony_ci| options | [NavigationOptions](#navigationoptions12) | No | Navigation options.| 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci### replacePathByName<sup>11+</sup> 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_cireplacePathByName(name: string, param: Object, animated?: boolean): void 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ciReplaces the top of the navigation stack with the page specified by **name**. 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**Parameters** 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 750e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 751e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 752e41f4b71Sopenharmony_ci| param | Object | Yes | Detailed parameters of the navigation destination page.| 753e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci### removeByIndexes<sup>11+</sup> 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ciremoveByIndexes(indexes: Array<number\>): number 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ciRemoves the navigation destination pages specified by **indexes** from the navigation stack. 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci**Parameters** 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 768e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 769e41f4b71Sopenharmony_ci| indexes | Array<number\> | Yes | Array of indexes of the navigation destination pages to remove. | 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci**Return value** 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci| Type | Description | 774e41f4b71Sopenharmony_ci| ----------- | ------------------------ | 775e41f4b71Sopenharmony_ci| number | Number of the navigation destination pages removed.| 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci### removeByName<sup>11+</sup> 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ciremoveByName(name: string): number 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ciRemoves the navigation destination page specified by **name** from the navigation stack. 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci**Parameters** 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 790e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 791e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page to remove. | 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**Return value** 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci| Type | Description | 796e41f4b71Sopenharmony_ci| ----------- | ------------------------ | 797e41f4b71Sopenharmony_ci| number | Number of the navigation destination pages removed.| 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci### removeByNavDestinationId<sup>12+</sup> 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ciremoveByNavDestinationId(navDestinationId: string): boolean 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ciRemoves the navigation destination page specified by **navDestinationId** from the navigation stack. **navDestinationId** can be obtained from the [onReady](ts-basic-components-navdestination.md#onready11) callback of **NavDestination** or from [NavDestinationInfo](../js-apis-arkui-observer.md#navdestinationinfo). 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci**Parameters** 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 812e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 813e41f4b71Sopenharmony_ci| navDestinationId | string | Yes | Unique ID of the navigation destination page to remove. | 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ci**Return value** 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci| Type | Description | 818e41f4b71Sopenharmony_ci| ----------- | ------------------------ | 819e41f4b71Sopenharmony_ci| boolean | Whether the page is removed successfully. The value **true** indicates that the page is removed successfully.| 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci### pop<sup>10+</sup> 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_cipop(animated?: boolean): NavPathInfo | undefined 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ciPops the top element out of the navigation stack. 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci**Parameters** 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 834e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 835e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ci**Return value** 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci| Type | Description | 840e41f4b71Sopenharmony_ci| ----------- | ------------------------ | 841e41f4b71Sopenharmony_ci| [NavPathInfo](#navpathinfo10) | Returns the information about the navigation destination page at the top of the stack.| 842e41f4b71Sopenharmony_ci| undefined | Returns **undefined** if the navigation stack is empty. | 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci### pop<sup>11+</sup> 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_cipop(result: Object, animated?: boolean): NavPathInfo | undefined 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ciPops the top element out of the navigation stack and invokes the **onPop** callback to pass the page processing result. 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ci**Parameters** 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 857e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 858e41f4b71Sopenharmony_ci| result | Object | Yes| Custom processing result on the page. The boolean type is not supported.| 859e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci**Return value** 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci| Type | Description | 864e41f4b71Sopenharmony_ci| ----------- | ------------------------ | 865e41f4b71Sopenharmony_ci| [NavPathInfo](#navpathinfo10) | Returns the information about the navigation destination page at the top of the stack.| 866e41f4b71Sopenharmony_ci| undefined | Returns **undefined** if the navigation stack is empty. | 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci### popToName<sup>10+</sup> 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_cipopToName(name: string, animated?: boolean): number 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_ciPops pages until the first navigation destination page that matches **name** from the bottom of the navigation stack is at the top of the stack. 873e41f4b71Sopenharmony_ci 874e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci**Parameters** 879e41f4b71Sopenharmony_ci 880e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 881e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------------- | 882e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page.| 883e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci**Return value** 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci| Type | Description | 888e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | 889e41f4b71Sopenharmony_ci| number | Returns the index of the first navigation destination page that matches **name** from the bottom of the navigation stack; returns **-1** if such a page does not exist.| 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci### popToName<sup>11+</sup> 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_cipopToName(name: string, result: Object, animated?: boolean): number 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ciPops pages until the first navigation destination page that matches **name** from the bottom of the navigation stack is at the top of the stack. This API uses the **onPop** callback to pass in the page processing result. 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**Parameters** 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 904e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------------- | 905e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page.| 906e41f4b71Sopenharmony_ci| result | Object | Yes| Custom processing result on the page. The boolean type is not supported.| 907e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci**Return value** 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci| Type | Description | 912e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | 913e41f4b71Sopenharmony_ci| number | Returns the index of the first navigation destination page that matches **name** from the bottom of the navigation stack; returns **-1** if such a page does not exist.| 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci### popToIndex<sup>10+</sup> 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_cipopToIndex(index: number, animated?: boolean): void 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ciReturns the navigation stack to the page specified by **index**. 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_ci**Parameters** 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 928e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 929e41f4b71Sopenharmony_ci| index | number | Yes | Index of the navigation destination page.| 930e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci### popToIndex<sup>11+</sup> 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_cipopToIndex(index: number, result: Object, animated?: boolean): void 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ciReturns the navigation stack to the page specified by **index** and invokes the **onPop** callback to pass the page processing result. 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**Parameters** 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 945e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 946e41f4b71Sopenharmony_ci| index | number | Yes | Index of the navigation destination page.| 947e41f4b71Sopenharmony_ci| result | Object | Yes| Custom processing result on the page. The boolean type is not supported.| 948e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci### moveToTop<sup>10+</sup> 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_cimoveToTop(name: string, animated?: boolean): number 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ciMoves the first navigation destination page that matches **name** from the bottom of the navigation stack to the top of the stack 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci**Parameters** 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 963e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------------- | 964e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page.| 965e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci**Return value** 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci| Type | Description | 970e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | 971e41f4b71Sopenharmony_ci| number | Returns the index of the first navigation destination page that matches **name** from the bottom of the navigation stack; returns **-1** if such a page does not exist.| 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ci### moveIndexToTop<sup>10+</sup> 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_cimoveIndexToTop(index: number, animated?: boolean): void 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ciMoves to the top of the navigation stack the navigation destination page specified by **index**. 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci**Parameters** 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 986e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 987e41f4b71Sopenharmony_ci| index | number | Yes | Index of the navigation destination page.| 988e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci### clear<sup>10+</sup> 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ciclear(animated?: boolean): void 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ciClears the navigation stack. 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 999e41f4b71Sopenharmony_ci 1000e41f4b71Sopenharmony_ci**Parameters** 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1003e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 1004e41f4b71Sopenharmony_ci| animated<sup>11+</sup> | boolean | No | Whether to support transition animation.<br>Default value: **true**| 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci### getAllPathName<sup>10+</sup> 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_cigetAllPathName(): Array<string\> 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ciObtains the names of all navigation destination pages in the navigation stack. 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1015e41f4b71Sopenharmony_ci 1016e41f4b71Sopenharmony_ci**Return value** 1017e41f4b71Sopenharmony_ci 1018e41f4b71Sopenharmony_ci| Type | Description | 1019e41f4b71Sopenharmony_ci| -------------- | -------------------------- | 1020e41f4b71Sopenharmony_ci| Array<string\> | Names of all navigation destination pages in the navigation stack.| 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci### getParamByIndex<sup>10+</sup> 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_cigetParamByIndex(index: number): unknown | undefined 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ciObtains the parameter information of the navigation destination page specified by **index**. 1027e41f4b71Sopenharmony_ci 1028e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci**Parameters** 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1035e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 1036e41f4b71Sopenharmony_ci| index | number | Yes | Index of the navigation destination page.| 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**Return value** 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci| Type | Description | 1041e41f4b71Sopenharmony_ci| --------- | -------------------------- | 1042e41f4b71Sopenharmony_ci| unknown | Returns the parameter information of the matching navigation destination page.| 1043e41f4b71Sopenharmony_ci| undefined | Returns **undefined** if the passed index is invalid. | 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci### getParamByName<sup>10+</sup> 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_cigetParamByName(name: string): Array<unknown\> 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ciObtains the parameter information of all the navigation destination pages that match **name**. 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci**Parameters** 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1058e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------------- | 1059e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page.| 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci**Return value** 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci| Type | Description | 1064e41f4b71Sopenharmony_ci| --------------- | --------------------------------- | 1065e41f4b71Sopenharmony_ci| Array<unknown\> | Parameter information of all the matching navigation destination pages.| 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci### getIndexByName<sup>10+</sup> 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_cigetIndexByName(name: string): Array<number\> 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ciObtains the indexes of all the navigation destination pages that match **name**. 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**Parameters** 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1080e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------------- | 1081e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page.| 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**Return value** 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci| Type | Description | 1086e41f4b71Sopenharmony_ci| -------------- | --------------------------------- | 1087e41f4b71Sopenharmony_ci| Array<number\> | Indexes of all the matching navigation destination pages.| 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci### size<sup>10+</sup> 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_cisize(): number 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ciObtains the stack size. 1094e41f4b71Sopenharmony_ci 1095e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1098e41f4b71Sopenharmony_ci 1099e41f4b71Sopenharmony_ci**Return value** 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci| Type | Description | 1102e41f4b71Sopenharmony_ci| ------ | ------ | 1103e41f4b71Sopenharmony_ci| number | Stack size.| 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci### disableAnimation<sup>11+</sup> 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_cidisableAnimation(value: boolean): void 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_ciDisables or enables the transition animation in the **Navigation** component. 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**Parameters** 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1118e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------- | 1119e41f4b71Sopenharmony_ci| value | boolean | No | Whether to disable the transition animation.<br>Default value: **false**| 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci### getParent<sup>11+</sup> 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_cigetParent(): NavPathStack | null 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ciObtains the parent navigation path stack.<br>When a **Navigation** component is nested (directly or indirectly) insider another **Navigation** component, the internal one can obtain the navigation path stack of the external one. 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci**Return value** 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci| Type | Description | 1134e41f4b71Sopenharmony_ci| ------ | ------ | 1135e41f4b71Sopenharmony_ci| [NavPathStack](#navpathstack10) \| null | Navigation path stack of the external **Navigation** component inside which the current **Navigation** component is nested. If no nesting is involved, **null** is returned.| 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci### setInterception<sup>12+</sup> 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_cisetInterception(interception: NavigationInterception): void 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ciSets the interception callback for navigation page redirection. 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_ci**Parameters** 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1150e41f4b71Sopenharmony_ci| ---- | ---- | --- | ---| 1151e41f4b71Sopenharmony_ci|interception| [NavigationInterception](#navigationinterception12)| Yes| Object to be intercepted during navigation redirection.| 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci## NavPathInfo<sup>10+</sup> 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ciProvides the navigation page information. 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci### constructor 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ciconstructor(name: string, param: unknown, onPop?: Callback\<PopInfo>, isEntry?: boolean) 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci**Parameters** 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1168e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 1169e41f4b71Sopenharmony_ci| name | string | Yes | Name of the navigation destination page. | 1170e41f4b71Sopenharmony_ci| param | unknown | No | Detailed parameters of the navigation destination page.| 1171e41f4b71Sopenharmony_ci| onPop<sup>11+</sup> | Callback\<[PopInfo](#popinfo11)> | No| Callback returned when **pop** is called on the navigation destination page.| 1172e41f4b71Sopenharmony_ci| isEntry<sup>12+</sup> | boolean | No| Whether the navigation destination page is the entry page.<br>Default value: **false**<br>The value of this parameter is reviewed or reset under the following conditions:<br>- When a global back event is triggered on the current navigation destination page.<br> - When the application is switched to the background.<br>**NOTE**<br>The navigation destination page serving as an entry does not respond to the in-app global back events; instead, it directly triggers the global back event between applications.| 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci## PopInfo<sup>11+</sup> 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ciProvides the callback information returned when a page is popped out of the navigation stack. 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci**Parameters** 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1185e41f4b71Sopenharmony_ci|------|-----|-----|-----| 1186e41f4b71Sopenharmony_ci| info | [NavPathInfo](#navpathinfo10) | Yes| Information about the current page when a back action is performed. The value is automatically obtained by the system.| 1187e41f4b71Sopenharmony_ci| result | Object | Yes| Result returned when a back action is performed. You must customize the object.| 1188e41f4b71Sopenharmony_ci 1189e41f4b71Sopenharmony_ci## NavContentInfo<sup>11+</sup> 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ciProvides the destination information. 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci**Parameters** 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1200e41f4b71Sopenharmony_ci|-------|-------|------|-------| 1201e41f4b71Sopenharmony_ci| name | string | No| Name of the navigation destination. If the view is a root view (**NavBar**), the return value is **undefined**.| 1202e41f4b71Sopenharmony_ci| index | number | Yes| Index of the navigation destination in the navigation stack. If the view is a root view (**NavBar**), the return value is **-1**.| 1203e41f4b71Sopenharmony_ci| mode | [NavDestinationMode](ts-basic-components-navdestination.md#navdestinationmode11) | No| Mode of the navigation destination. If the view is a root view (**NavBar**), the return value is **undefined**.| 1204e41f4b71Sopenharmony_ci| param<sup>12+</sup> | Object | No| Parameters loaded on the navigation destination page.| 1205e41f4b71Sopenharmony_ci| navDestinationId<sup>12+</sup> | string | No| Unique identifier of the navigation destination page.| 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci## NavigationAnimatedTransition<sup>11+</sup> 1208e41f4b71Sopenharmony_ci 1209e41f4b71Sopenharmony_ciDefines the custom transition animation protocol. You need to implement this protocol to define the redirection animation of the navigation route. 1210e41f4b71Sopenharmony_ci 1211e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1212e41f4b71Sopenharmony_ci 1213e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_ci**Parameters** 1216e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1217e41f4b71Sopenharmony_ci|------|-----|-----|------| 1218e41f4b71Sopenharmony_ci| timeout | number | No| Animation timeout time.<br> Unit: ms<br> Default value: no default value for interactive animations; 1000 ms for non-interactive animations.| 1219e41f4b71Sopenharmony_ci| transition | (transitionProxy : [NavigationTransitionProxy](#navigationtransitionproxy-11)) => void | Yes| Callback for executing the custom transition animation.<br> **transitionProxy**: proxy for the custom transition animation.| 1220e41f4b71Sopenharmony_ci| onTransitionEnd | (success: boolean):void | No| Callback invoked when the transition is complete.<br> **success**: whether the transition is successful.| 1221e41f4b71Sopenharmony_ci| isInteractive<sup>12+</sup> | boolean | No| Whether the transition animation is interactive.<br> Default value: **false**| 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ci## NavigationTransitionProxy <sup>11+</sup> 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ciImplements a custom transition animation proxy. 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci### Attributes 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 1236e41f4b71Sopenharmony_ci|------|-------|-----|-------| 1237e41f4b71Sopenharmony_ci| from | [NavContentInfo](#navcontentinfo11) | Yes| Information about the exit page.| 1238e41f4b71Sopenharmony_ci| to | [NavContentInfo](#navcontentinfo11) | Yes| Information about the enter page.| 1239e41f4b71Sopenharmony_ci| isInteractive<sup>12+</sup> | boolean | No| Whether the transition animation is interactive.| 1240e41f4b71Sopenharmony_ci 1241e41f4b71Sopenharmony_ci### finishTransition 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_cifinishTransition(): void; 1244e41f4b71Sopenharmony_ci 1245e41f4b71Sopenharmony_ciFinishes this custom transition animation. This API must be manually called to end the animation. Otherwise, the system ends the animation when the timeout expires. 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci### cancelTransition<sup>12+</sup> 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_cicancelTransition?(): void; 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ciCancels this interactive transition animation, restoring the navigation stack to its state before page redirection. (Non-interactive transition animations cannot be canceled.) 1256e41f4b71Sopenharmony_ci 1257e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci### updateTransition<sup>12+</sup> 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ciupdateTransition?(progress: number): void; 1264e41f4b71Sopenharmony_ci 1265e41f4b71Sopenharmony_ciUpdates the progress of this interactive transition animation. (Non-interactive animations do not support setting the animation progress). 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1268e41f4b71Sopenharmony_ci 1269e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1270e41f4b71Sopenharmony_ci 1271e41f4b71Sopenharmony_ci**Parameters** 1272e41f4b71Sopenharmony_ci 1273e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1274e41f4b71Sopenharmony_ci|------|------|------|-----| 1275e41f4b71Sopenharmony_ci| progress | number | Yes| Progress percentage of the interactive transition animation. The value ranges from 0 to 1.| 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci## NavigationInterception<sup>12+</sup> 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_ciDescribes the object to be intercepted during navigation redirection. 1280e41f4b71Sopenharmony_ci 1281e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1286e41f4b71Sopenharmony_ci| ---- | ----- | ----- | ---- | 1287e41f4b71Sopenharmony_ci| willShow | [InterceptionShowCallback](#interceptionshowcallback12) | No| Interception before page redirection, allowing for stack operations. The setting takes effect in the current redirection.| 1288e41f4b71Sopenharmony_ci| didShow | [InterceptionShowCallback](#interceptionshowcallback12) | No| Callback after page redirection. The setting takes effect in the next redirection.| 1289e41f4b71Sopenharmony_ci| modeChange | [InterceptionModeCallback](#interceptionmodecallback12) | No| Callback invoked when the display mode of the **Navigation** component switches between single-column and dual-column.| 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci### InterceptionShowCallback<sup>12+</sup> 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_citype InterceptionShowCallback = (from: NavDestinationContext|NavBar, to: NavDestinationContext|NavBar, operation: NavigationOperation, isAnimated: boolean) => void 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_ciRepresents the interception callback before and after the navigation page. 1296e41f4b71Sopenharmony_ci 1297e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1302e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- | 1303e41f4b71Sopenharmony_ci| from | [NavDestinationContext](ts-basic-components-navdestination.md#navdestinationcontext11) \|[NavBar](#navbar12) | Yes| Information about the top page in the navigation stack before page redirection. The value **navBar** indicates that the top page is the home page.| 1304e41f4b71Sopenharmony_ci| to | [NavDestinationContext](ts-basic-components-navdestination.md#navdestinationcontext11) \|[NavBar](#navbar12) | Yes| Information about the top page in the navigation stack after page redirection. The value **navBar** indicates that the top page is the home page.| 1305e41f4b71Sopenharmony_ci| operation | [NavigationOperation](#navigationoperation11) | Yes| Current page redirection type.| 1306e41f4b71Sopenharmony_ci| isAnimated | boolean | Yes| Whether to support transition animation.| 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_ci### InterceptionModeCallback<sup>12+</sup> 1309e41f4b71Sopenharmony_ci 1310e41f4b71Sopenharmony_citype InterceptionModeCallback = (mode: NavigationMode) => void 1311e41f4b71Sopenharmony_ci 1312e41f4b71Sopenharmony_ciImplements an interception callback triggered when the display mode of the **Navigation** component switches between single-column and dual-column. 1313e41f4b71Sopenharmony_ci 1314e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1315e41f4b71Sopenharmony_ci 1316e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1317e41f4b71Sopenharmony_ci 1318e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 1319e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- | 1320e41f4b71Sopenharmony_ci| mode | [NavigationMode](#navigationmode9) | Yes| Display mode of the navigation bar.| 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci### NavBar<sup>12+</sup> 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_citype NavBar = 'navBar' 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ciDefines the name of the navigation home page. 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1331e41f4b71Sopenharmony_ci 1332e41f4b71Sopenharmony_ci| Type | Description | 1333e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1334e41f4b71Sopenharmony_ci| "navBar" | Navigation home page.| 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci## NavigationMenuItem 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1339e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | --------------- | 1340e41f4b71Sopenharmony_ci| value | string | Yes | Text of the menu item. Its visibility varies by the API version.<br>API version 9: visible.<br> API version 10: invisible.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1341e41f4b71Sopenharmony_ci| icon | string | No | Icon path of the menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1342e41f4b71Sopenharmony_ci| isEnabled<sup>12+</sup> | boolean | No | Enabled status.<br>**true** (default): enabled<br>**false**: disabled<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1343e41f4b71Sopenharmony_ci| action | () => void | No | Callback invoked when the menu item is selected.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1344e41f4b71Sopenharmony_ci| symbolIcon<sup>12+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No |Symbol icon for a single option on the menu bar. It has higher priority than **icon**.| 1345e41f4b71Sopenharmony_ci 1346e41f4b71Sopenharmony_ci## ToolbarItem<sup>10+</sup> 1347e41f4b71Sopenharmony_ci 1348e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1349e41f4b71Sopenharmony_ci 1350e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1351e41f4b71Sopenharmony_ci 1352e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1353e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 1354e41f4b71Sopenharmony_ci| value | ResourceStr | Yes | Text of the toolbar item. | 1355e41f4b71Sopenharmony_ci| icon | ResourceStr | No | Icon path of the toolbar item. | 1356e41f4b71Sopenharmony_ci| action | () => void | No | Callback invoked when the toolbar item is selected. | 1357e41f4b71Sopenharmony_ci| status | [ToolbarItemStatus](#toolbaritemstatus10) | No | Status of the toolbar item.<br>Default value: **ToolbarItemStatus.NORMAL**| 1358e41f4b71Sopenharmony_ci| activeIcon | ResourceStr | No | Icon path of the toolbar item in the active state. | 1359e41f4b71Sopenharmony_ci| symbolIcon<sup>12+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No | Symbol icon for a single option on the toolbar. It has higher priority than **icon**. | 1360e41f4b71Sopenharmony_ci| activeSymbolIcon<sup>12+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No | Symbol icon for a single option on the menu bar when it is in active state. It has higher priority than **icon**. | 1361e41f4b71Sopenharmony_ci 1362e41f4b71Sopenharmony_ci## ToolbarItemStatus<sup>10+</sup> 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1367e41f4b71Sopenharmony_ci 1368e41f4b71Sopenharmony_ci| Name | Description | 1369e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1370e41f4b71Sopenharmony_ci| NORMAL | Normal state. In this state, the toolbar item takes on the default style and can switch to another state-specific style by responding to the hover, press, and focus events.| 1371e41f4b71Sopenharmony_ci| DISABLED | Disabled state. In this state, the toolbar item is disabled and does not allow for user interactions.| 1372e41f4b71Sopenharmony_ci| ACTIVE | Active state. In this state, the toolbar item can update its icon to the one specified by **activeIcon** by responding to a click event.| 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci## NavigationTitleMode 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1379e41f4b71Sopenharmony_ci 1380e41f4b71Sopenharmony_ci| Name | Description | 1381e41f4b71Sopenharmony_ci| ---- | ---------------------------------------- | 1382e41f4b71Sopenharmony_ci| Free | When the content is more than one screen in a scrollable component, the main title shrinks as the content scrolls down (the subtitle fades out with its size remaining unchanged) and restores as the content scrolls up to the top.<br>**NOTE**<br>The effect where the main title's size changes in response to content scrolling is effective only when **title** is set to **ResourceStr** or **NavigationCommonTitle**. If **title** is set to any other value type, the main title changes in mere location when pulled down.<br>For this effect to work when the content is less than one screen in a scrollable component, set the **options** parameter of the scrollable component's [edgeEffect](ts-container-list.md#attributes) attribute to **true**. In the non-scrolling state, the height of the title bar is the same as in **Full** mode; in the scrolling state, the minimum height of the title bar is the same as in **Mini** mode.| 1383e41f4b71Sopenharmony_ci| Mini | The title is fixed at mini mode.<br>Default value:<br>In versions earlier than API version 12, if there is only a main title, the title bar height is 56 vp; if there is both a main title and a subtitle, the title bar height is 82 vp.<br> Since API version 12, the title bar height is 56 vp. | 1384e41f4b71Sopenharmony_ci| Full | The title is fixed at full mode.<br>Default value: If there is only a main title, the title bar height is 112 vp; if there is both a main title and a subtitle, the title bar height is 138 vp. | 1385e41f4b71Sopenharmony_ci 1386e41f4b71Sopenharmony_ci## NavigationCommonTitle<sup>9+</sup> 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1393e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------ | 1394e41f4b71Sopenharmony_ci| main | string | Yes | Main title.| 1395e41f4b71Sopenharmony_ci| sub | string | Yes | Subtitle.| 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ci## NavigationCustomTitle<sup>9+</sup> 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1400e41f4b71Sopenharmony_ci 1401e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1402e41f4b71Sopenharmony_ci 1403e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1404e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | -------- | 1405e41f4b71Sopenharmony_ci| builder | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Content of the title bar.| 1406e41f4b71Sopenharmony_ci| height | [TitleHeight](#titleheight9) \| [Length](ts-types.md#length) | Yes | Height of the title bar.| 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_ci## NavBarPosition<sup>9+</sup> 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1411e41f4b71Sopenharmony_ci 1412e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_ci| Name | Description | 1415e41f4b71Sopenharmony_ci| ----- | ---------------- | 1416e41f4b71Sopenharmony_ci| Start | When two columns are displayed, the main column is at the start of the main axis.| 1417e41f4b71Sopenharmony_ci| End | When two columns are displayed, the main column is at the end of the main axis.| 1418e41f4b71Sopenharmony_ci 1419e41f4b71Sopenharmony_ci## NavigationMode<sup>9+</sup> 1420e41f4b71Sopenharmony_ci 1421e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1422e41f4b71Sopenharmony_ci 1423e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1424e41f4b71Sopenharmony_ci 1425e41f4b71Sopenharmony_ci| Name | Description | 1426e41f4b71Sopenharmony_ci| ----- | ------------------------------------------------------------ | 1427e41f4b71Sopenharmony_ci| Stack | The navigation bar and content area are displayed independently of each other, which are equivalent to two pages. | 1428e41f4b71Sopenharmony_ci| Split | The navigation bar and content area are displayed in different columns.<br>The values of **navBarWidthRange** are represented by [minNavBarWidth,maxNavBarWidth].<br>1. When the value of **navBarWidth** is beyond the value range specified by **navBarWidthRange**, **navBarWidth** is set according to the following rules:<br>Value of **navBarWidth** < Value of **minNavBarWidth**: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Result of [Component width - Value of **minContentWidth** - Divider width (1 vp)] > Value of **maxNavBarWidth**: The value of **navBarWidth** is changed to that of **maxNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Result of [Component width - Value of **minContentWidth** - Divider width (1 vp)] < Value of **maxNavBarWidth**: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **navBarWidth** > Value of **maxNavBarWidth** and Component width - Value of **minContentWidth** - Divider width (1 vp) is within the value range specified by **navBarWidthRange**: The value of **navBarWidth** is changed to Component width - Value of **minContentWidth** - Divider width (1 vp).<br>2. When the value of **navBarWidth** is within the value range specified by **navBarWidthRange**, **navBarWidth** is set according to the following rules:<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) > = Component width: The value of **navBarWidth** is changed to that of **minNavBarWidth**.<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width and Value of **navBarWidth** + Value of **minContentWidth** + Divider width (1 vp) > = Component width: The value of **navBarWidth** is changed to Component width - Value of **minContentWidth** - Divider width (1 vp).<br>Value of **minNavBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width and Value of **navBarWidth** + Value of **minContentWidth** + Divider width (1 vp) < Component width: The value of **navBarWidth** is the set value. <br>3. When the component size is decreased, the content area is shrunk until its width reaches the value defined by **minContentWidth**, and then the navigation bar is shrunk until its width reaches the value defined by **minNavBarWidth**; if the component size is further decreased, the content area is further shrunk until it disappears, and then navigation bar is shrunk.<br>4. When the navigation bar is set to a fixed size and the component size is continuously decreased, the navigation bar is shrunk.<br>5. If only **navBarWidth** is set, the width of the navigation bar is fixed at the value of **navBarWidth**, and the divider cannot be dragged.| 1429e41f4b71Sopenharmony_ci| Auto | In API version 9 and earlier versions: If the window width is greater than or equal to 520 vp, the Split mode is used; otherwise, the Stack mode is used.<br>In API version 10 and later versions: If the window width is greater than or equal to 600 vp, the Split mode is used; otherwise, the Stack mode is used. 600 vp = minNavBarWidth (240 vp) + minContentWidth (360 vp).| 1430e41f4b71Sopenharmony_ci 1431e41f4b71Sopenharmony_ci## TitleHeight<sup>9+</sup> 1432e41f4b71Sopenharmony_ci 1433e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1436e41f4b71Sopenharmony_ci 1437e41f4b71Sopenharmony_ci| Name | Description | 1438e41f4b71Sopenharmony_ci| ----------- | -------------------------- | 1439e41f4b71Sopenharmony_ci| MainOnly | Recommended height (56 vp) of the title bar when only the main title is available. | 1440e41f4b71Sopenharmony_ci| MainWithSub | Recommended height (82 vp) of the title bar when both the main title and subtitle exist.| 1441e41f4b71Sopenharmony_ci 1442e41f4b71Sopenharmony_ci## NavigationOperation<sup>11+</sup> 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci| Name | Description | 1449e41f4b71Sopenharmony_ci|---------|------| 1450e41f4b71Sopenharmony_ci|PUSH | The transition is enter transition.| 1451e41f4b71Sopenharmony_ci|POP | The transition is exit transition.| 1452e41f4b71Sopenharmony_ci| REPLACE | The transition is page replacement.| 1453e41f4b71Sopenharmony_ci 1454e41f4b71Sopenharmony_ci## BarStyle<sup>12+</sup> 1455e41f4b71Sopenharmony_ci 1456e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci| Name | Description | 1461e41f4b71Sopenharmony_ci|---------|------| 1462e41f4b71Sopenharmony_ci|STANDARD | The title bar and content area are arranged in a vertical layout.| 1463e41f4b71Sopenharmony_ci|STACK | The title bar and the content area are arranged in a stacked layout, with the title bar positioned above the content area.| 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci## NavigationTitleOptions<sup>11+</sup> 1466e41f4b71Sopenharmony_ci 1467e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1468e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | --------------- | 1469e41f4b71Sopenharmony_ci| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | No | Background color of the title bar. If this parameter is not set, the default color is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1470e41f4b71Sopenharmony_ci| backgroundBlurStyle | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the title bar. If this parameter is not set, the background blur effect is disabled.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1471e41f4b71Sopenharmony_ci| barStyle<sup>12+</sup> | [BarStyle](#barstyle12) | No | Layout of the title bar.<br>Default value: **BarStyle.STANDARD**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1472e41f4b71Sopenharmony_ci| paddingStart<sup>12+</sup> | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | No | Padding at the start of the title bar.<br>Only supported in one of the following scenarios:<br>1. Displaying the back icon, that is, [hideBackButton](#hidebackbutton) is **false**<br>2. Using a non-custom title, that is, the [title value](#title) type is **ResourceStr** or **NavigationCommonTitle**<br>Default value:<br>LengthMetrics.resource(**$r('sys.float.margin_left')**)<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1473e41f4b71Sopenharmony_ci| paddingEnd<sup>12+</sup> | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | No | Padding at the end of the title bar.<br>Only supported in one of the following scenarios:<br>1. Using a non-custom menu, that is, the [menu value](#menus) is Array<NavigationMenuItem><br>2. Using a non-custom menu without a menu in the upper right corner, that is, the [title value](#title) type is **ResourceStr** or **NavigationCommonTitle**<br>Default value:<br>LengthMetrics.resource(**$r('sys.float.margin_right')**)<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1474e41f4b71Sopenharmony_ci| mainTitleModifier<sup>13+</sup> | [TextModifier](./ts-universal-attributes-attribute-modifier.md) | No| Main title attribute modifier.<br>Notes for using this modifier:<br>1. Attribute settings configured by this modifier will override the system's default attribute settings. For example, if the modifier is used to set font size attributes, such as **fontSize**, **maxFontSize**, and **minFontSize**, the settings will take precedence over the system's default settings for size-related attributes.<br>2. If no modifier is used or an invalid value is set, the system reverts to its default settings.<br>3. In [Free](#navigationtitlemode) mode, setting the font size will disable the effect where the main title's size changes in response to content scrolling.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 1475e41f4b71Sopenharmony_ci| subTitleModifier<sup>13+</sup> | [TextModifier](./ts-universal-attributes-attribute-modifier.md) | No| Subtitle attribute modifier.<br>Notes for using this modifier:<br>1. Attribute settings configured by this modifier will override the system's default attribute settings. For example, if the modifier is used to set font size attributes, such as **fontSize**, **maxFontSize**, and **minFontSize**, the settings will take precedence over the system's default settings for size-related attributes.<br>2. If no modifier is used or an invalid value is set, the system reverts to its default settings.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_ci## NavigationToolbarOptions<sup>11+</sup> 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1482e41f4b71Sopenharmony_ci 1483e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1484e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | --------------- | 1485e41f4b71Sopenharmony_ci| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | No | Background color of the toolbar. If this parameter is not set, the default color is used.| 1486e41f4b71Sopenharmony_ci| backgroundBlurStyle | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the toolbar. If this parameter is not set, the background blur effect is disabled.| 1487e41f4b71Sopenharmony_ci 1488e41f4b71Sopenharmony_ci## LaunchMode<sup>12+</sup> 1489e41f4b71Sopenharmony_ci 1490e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1491e41f4b71Sopenharmony_ci 1492e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1493e41f4b71Sopenharmony_ci 1494e41f4b71Sopenharmony_ci| Name | Description | 1495e41f4b71Sopenharmony_ci| --------- | ------ | 1496e41f4b71Sopenharmony_ci| STANDARD | Default navigation stack operation mode.<br>In this mode, push operations add the specified **NavDestination** page to the stack; replace operations replace the current top **NavDestination** page.| 1497e41f4b71Sopenharmony_ci| MOVE_TO_TOP_SINGLETON | This mode searches from the bottom to the top of the navigation stack. If a **NavDestination** page with the specified name exists, it moves that page to the top of the stack (for a replace operation, it replaces the last top **NavDestination** page with the specified one); otherwise, it behaves like **STANDARD**.| 1498e41f4b71Sopenharmony_ci| POP_TO_SINGLETON | This mode searches from the bottom to the top of the navigation stack. If a **NavDestination** page with the specified name exists, it removes all **NavDestination** pages above it(for a replace operation, it replaces the last top **NavDestination** page with the specified one); otherwise, it behaves like **STANDARD**.| 1499e41f4b71Sopenharmony_ci| NEW_INSTANCE | This mode creates an instance of **NavDestination**. Compared with **STANDARD**, this mode does not reuse the instance with the same name in the stack.| 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ci## NavigationOptions<sup>12+</sup> 1502e41f4b71Sopenharmony_ci 1503e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1508e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | --------------- | 1509e41f4b71Sopenharmony_ci| launchMode | [LaunchMode](#launchmode12) | No | Navigation stack operation mode.<br>Default value: **LaunchMode.STANDARD**| 1510e41f4b71Sopenharmony_ci| animated | boolean | No | Whether to support transition animation.<br>Default value: **true**| 1511e41f4b71Sopenharmony_ci 1512e41f4b71Sopenharmony_ci## Example 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ciThe sample effect is subject to the actual device. 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_ci### Example 1 1517e41f4b71Sopenharmony_ci 1518e41f4b71Sopenharmony_ciThis example demonstrates the page layout of the **Navigation** component. 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci```ts 1521e41f4b71Sopenharmony_ci// xxx.ets 1522e41f4b71Sopenharmony_ciclass A { 1523e41f4b71Sopenharmony_ci text: string = '' 1524e41f4b71Sopenharmony_ci num: number = 0 1525e41f4b71Sopenharmony_ci} 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_ci@Entry 1528e41f4b71Sopenharmony_ci@Component 1529e41f4b71Sopenharmony_cistruct NavigationExample { 1530e41f4b71Sopenharmony_ci private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 1531e41f4b71Sopenharmony_ci @State currentIndex: number = 0 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ci @Builder NavigationTitle() { 1534e41f4b71Sopenharmony_ci Column() { 1535e41f4b71Sopenharmony_ci Text('Title') 1536e41f4b71Sopenharmony_ci .fontColor('#182431') 1537e41f4b71Sopenharmony_ci .fontSize(30) 1538e41f4b71Sopenharmony_ci .lineHeight(41) 1539e41f4b71Sopenharmony_ci .fontWeight(700) 1540e41f4b71Sopenharmony_ci Text('subtitle') 1541e41f4b71Sopenharmony_ci .fontColor('#182431') 1542e41f4b71Sopenharmony_ci .fontSize(14) 1543e41f4b71Sopenharmony_ci .lineHeight(19) 1544e41f4b71Sopenharmony_ci .opacity(0.4) 1545e41f4b71Sopenharmony_ci .margin({ top: 2, bottom: 20 }) 1546e41f4b71Sopenharmony_ci }.alignItems(HorizontalAlign.Start) 1547e41f4b71Sopenharmony_ci } 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci @Builder NavigationMenus() { 1550e41f4b71Sopenharmony_ci Row() { 1551e41f4b71Sopenharmony_ci Image('resources/base/media/ic_public_add.svg') 1552e41f4b71Sopenharmony_ci .width(24) 1553e41f4b71Sopenharmony_ci .height(24) 1554e41f4b71Sopenharmony_ci Image('resources/base/media/ic_public_add.svg') 1555e41f4b71Sopenharmony_ci .width(24) 1556e41f4b71Sopenharmony_ci .height(24) 1557e41f4b71Sopenharmony_ci .margin({ left: 24 }) 1558e41f4b71Sopenharmony_ci Image('common/ic_public_more.svg') 1559e41f4b71Sopenharmony_ci .width(24) 1560e41f4b71Sopenharmony_ci .height(24) 1561e41f4b71Sopenharmony_ci .margin({ left: 24 }) 1562e41f4b71Sopenharmony_ci } 1563e41f4b71Sopenharmony_ci } 1564e41f4b71Sopenharmony_ci 1565e41f4b71Sopenharmony_ci build() { 1566e41f4b71Sopenharmony_ci Column() { 1567e41f4b71Sopenharmony_ci Navigation() { 1568e41f4b71Sopenharmony_ci TextInput({ placeholder: 'search...' }) 1569e41f4b71Sopenharmony_ci .width('90%') 1570e41f4b71Sopenharmony_ci .height(40) 1571e41f4b71Sopenharmony_ci .backgroundColor('#FFFFFF') 1572e41f4b71Sopenharmony_ci .margin({ top: 8 }) 1573e41f4b71Sopenharmony_ci 1574e41f4b71Sopenharmony_ci List({ space: 12, initialIndex: 0 }) { 1575e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 1576e41f4b71Sopenharmony_ci ListItem() { 1577e41f4b71Sopenharmony_ci Text('' + item) 1578e41f4b71Sopenharmony_ci .width('90%') 1579e41f4b71Sopenharmony_ci .height(72) 1580e41f4b71Sopenharmony_ci .backgroundColor('#FFFFFF') 1581e41f4b71Sopenharmony_ci .borderRadius(24) 1582e41f4b71Sopenharmony_ci .fontSize(16) 1583e41f4b71Sopenharmony_ci .fontWeight(500) 1584e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1585e41f4b71Sopenharmony_ci } 1586e41f4b71Sopenharmony_ci }, (item: number) => item.toString()) 1587e41f4b71Sopenharmony_ci } 1588e41f4b71Sopenharmony_ci .height(324) 1589e41f4b71Sopenharmony_ci .width('100%') 1590e41f4b71Sopenharmony_ci .margin({ top: 12, left: '10%' }) 1591e41f4b71Sopenharmony_ci } 1592e41f4b71Sopenharmony_ci .title(this.NavigationTitle) 1593e41f4b71Sopenharmony_ci .menus(this.NavigationMenus) 1594e41f4b71Sopenharmony_ci .titleMode(NavigationTitleMode.Full) 1595e41f4b71Sopenharmony_ci .toolbarConfiguration([ 1596e41f4b71Sopenharmony_ci { 1597e41f4b71Sopenharmony_ci value: $r("app.string.navigation_toolbar_add"), 1598e41f4b71Sopenharmony_ci icon: $r("app.media.ic_public_highlightsed") 1599e41f4b71Sopenharmony_ci }, 1600e41f4b71Sopenharmony_ci { 1601e41f4b71Sopenharmony_ci value: $r("app.string.navigation_toolbar_app"), 1602e41f4b71Sopenharmony_ci icon: $r("app.media.ic_public_highlights") 1603e41f4b71Sopenharmony_ci }, 1604e41f4b71Sopenharmony_ci { 1605e41f4b71Sopenharmony_ci value: $r("app.string.navigation_toolbar_collect"), 1606e41f4b71Sopenharmony_ci icon: $r("app.media.ic_public_highlights") 1607e41f4b71Sopenharmony_ci } 1608e41f4b71Sopenharmony_ci ]) 1609e41f4b71Sopenharmony_ci .hideTitleBar(false) 1610e41f4b71Sopenharmony_ci .hideToolBar(false) 1611e41f4b71Sopenharmony_ci .onTitleModeChange((titleModel: NavigationTitleMode) => { 1612e41f4b71Sopenharmony_ci console.info('titleMode' + titleModel) 1613e41f4b71Sopenharmony_ci }) 1614e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 1615e41f4b71Sopenharmony_ci } 1616e41f4b71Sopenharmony_ci} 1617e41f4b71Sopenharmony_ci``` 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ci 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ci### Example 2 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ciThis example demonstrates the use of methods in **NavPathStack** and route interception. 1626e41f4b71Sopenharmony_ci 1627e41f4b71Sopenharmony_ci```ts 1628e41f4b71Sopenharmony_ci// Index.ets 1629e41f4b71Sopenharmony_ci 1630e41f4b71Sopenharmony_ci@Entry 1631e41f4b71Sopenharmony_ci@Component 1632e41f4b71Sopenharmony_cistruct NavigationExample { 1633e41f4b71Sopenharmony_ci pageInfos: NavPathStack = new NavPathStack() 1634e41f4b71Sopenharmony_ci isUseInterception: boolean = false; 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_ci registerInterception() { 1637e41f4b71Sopenharmony_ci this.pageInfos.setInterception({ 1638e41f4b71Sopenharmony_ci willShow: (from: NavDestinationContext | "navBar", to: NavDestinationContext | "navBar", 1639e41f4b71Sopenharmony_ci operation: NavigationOperation, animated: boolean) => { 1640e41f4b71Sopenharmony_ci if (!this.isUseInterception) { 1641e41f4b71Sopenharmony_ci return; 1642e41f4b71Sopenharmony_ci } 1643e41f4b71Sopenharmony_ci if (typeof to === "string") { 1644e41f4b71Sopenharmony_ci console.log("target page is navigation home"); 1645e41f4b71Sopenharmony_ci return; 1646e41f4b71Sopenharmony_ci } 1647e41f4b71Sopenharmony_ci // redirect target page.Change pageTwo to pageOne. 1648e41f4b71Sopenharmony_ci let target: NavDestinationContext = to as NavDestinationContext; 1649e41f4b71Sopenharmony_ci if (target.pathInfo.name === 'pageTwo') { 1650e41f4b71Sopenharmony_ci target.pathStack.pop(); 1651e41f4b71Sopenharmony_ci target.pathStack.pushPathByName('pageOne', null); 1652e41f4b71Sopenharmony_ci } 1653e41f4b71Sopenharmony_ci }, 1654e41f4b71Sopenharmony_ci didShow: (from: NavDestinationContext | "navBar", to: NavDestinationContext | "navBar", 1655e41f4b71Sopenharmony_ci operation: NavigationOperation, isAnimated: boolean) => { 1656e41f4b71Sopenharmony_ci if (!this.isUseInterception) { 1657e41f4b71Sopenharmony_ci return; 1658e41f4b71Sopenharmony_ci } 1659e41f4b71Sopenharmony_ci if (typeof from === "string") { 1660e41f4b71Sopenharmony_ci console.log("current transition is from navigation home"); 1661e41f4b71Sopenharmony_ci } else { 1662e41f4b71Sopenharmony_ci console.log(`current transition is from ${(from as NavDestinationContext).pathInfo.name}`) 1663e41f4b71Sopenharmony_ci } 1664e41f4b71Sopenharmony_ci if (typeof to === "string") { 1665e41f4b71Sopenharmony_ci console.log("current transition to is navBar"); 1666e41f4b71Sopenharmony_ci } else { 1667e41f4b71Sopenharmony_ci console.log(`current transition is to ${(to as NavDestinationContext).pathInfo.name}`); 1668e41f4b71Sopenharmony_ci } 1669e41f4b71Sopenharmony_ci }, 1670e41f4b71Sopenharmony_ci modeChange: (mode: NavigationMode) => { 1671e41f4b71Sopenharmony_ci if (!this.isUseInterception) { 1672e41f4b71Sopenharmony_ci return; 1673e41f4b71Sopenharmony_ci } 1674e41f4b71Sopenharmony_ci console.log(`current navigation mode is ${mode}`); 1675e41f4b71Sopenharmony_ci } 1676e41f4b71Sopenharmony_ci }) 1677e41f4b71Sopenharmony_ci } 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ci build() { 1680e41f4b71Sopenharmony_ci Navigation(this.pageInfos) { 1681e41f4b71Sopenharmony_ci Column() { 1682e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 1683e41f4b71Sopenharmony_ci .width('80%') 1684e41f4b71Sopenharmony_ci .height(40) 1685e41f4b71Sopenharmony_ci .margin(20) 1686e41f4b71Sopenharmony_ci .onClick(() => { 1687e41f4b71Sopenharmony_ci this.pageInfos.pushPath({ name:'pageOne'}) // Push the navigation destination page specified by name to the navigation stack. 1688e41f4b71Sopenharmony_ci }) 1689e41f4b71Sopenharmony_ci Button('use interception', { stateEffect: true, type: ButtonType.Capsule }) 1690e41f4b71Sopenharmony_ci .width('80%') 1691e41f4b71Sopenharmony_ci .height(40) 1692e41f4b71Sopenharmony_ci .margin(20) 1693e41f4b71Sopenharmony_ci .onClick(() => { 1694e41f4b71Sopenharmony_ci this.isUseInterception = !this.isUseInterception; 1695e41f4b71Sopenharmony_ci if (this.isUseInterception) { 1696e41f4b71Sopenharmony_ci this.registerInterception(); 1697e41f4b71Sopenharmony_ci } else { 1698e41f4b71Sopenharmony_ci this.pageInfos.setInterception(undefined); 1699e41f4b71Sopenharmony_ci } 1700e41f4b71Sopenharmony_ci }) 1701e41f4b71Sopenharmony_ci } 1702e41f4b71Sopenharmony_ci }.title('NavIndex') 1703e41f4b71Sopenharmony_ci } 1704e41f4b71Sopenharmony_ci} 1705e41f4b71Sopenharmony_ci``` 1706e41f4b71Sopenharmony_ci```ts 1707e41f4b71Sopenharmony_ci// PageOne.ets 1708e41f4b71Sopenharmony_ciclass TmpClass{ 1709e41f4b71Sopenharmony_ci count:number=10 1710e41f4b71Sopenharmony_ci} 1711e41f4b71Sopenharmony_ci 1712e41f4b71Sopenharmony_ci@Builder 1713e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 1714e41f4b71Sopenharmony_ci PageOne() 1715e41f4b71Sopenharmony_ci} 1716e41f4b71Sopenharmony_ci 1717e41f4b71Sopenharmony_ci@Component 1718e41f4b71Sopenharmony_ciexport struct PageOne { 1719e41f4b71Sopenharmony_ci 1720e41f4b71Sopenharmony_ci pageInfos: NavPathStack = new NavPathStack() 1721e41f4b71Sopenharmony_ci 1722e41f4b71Sopenharmony_ci build() { 1723e41f4b71Sopenharmony_ci NavDestination() { 1724e41f4b71Sopenharmony_ci Column() { 1725e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 1726e41f4b71Sopenharmony_ci .width('80%') 1727e41f4b71Sopenharmony_ci .height(40) 1728e41f4b71Sopenharmony_ci .margin(20) 1729e41f4b71Sopenharmony_ci .onClick(() => { 1730e41f4b71Sopenharmony_ci let tmp = new TmpClass() 1731e41f4b71Sopenharmony_ci this.pageInfos.pushPathByName('pageTwo', tmp) // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 1732e41f4b71Sopenharmony_ci }) 1733e41f4b71Sopenharmony_ci Button('singletonLaunchMode', { stateEffect: true, type: ButtonType.Capsule }) 1734e41f4b71Sopenharmony_ci .width('80%') 1735e41f4b71Sopenharmony_ci .height(40) 1736e41f4b71Sopenharmony_ci .margin(20) 1737e41f4b71Sopenharmony_ci .onClick(() => { 1738e41f4b71Sopenharmony_ci this.pageInfos.pushPath({ name: 'pageOne' }, { launchMode: LaunchMode.MOVE_TO_TOP_SINGLETON }) // Search from the bottom to the top of the stack. If the page with the specified name exists, move that page to the top of the stack. 1739e41f4b71Sopenharmony_ci }) 1740e41f4b71Sopenharmony_ci Button('popToname', { stateEffect: true, type: ButtonType.Capsule }) 1741e41f4b71Sopenharmony_ci .width('80%') 1742e41f4b71Sopenharmony_ci .height(40) 1743e41f4b71Sopenharmony_ci .margin(20) 1744e41f4b71Sopenharmony_ci .onClick(() => { 1745e41f4b71Sopenharmony_ci this.pageInfos.popToName('pageTwo') // Pop the first navigation destination page that matches the value of name to the top of the navigation stack. 1746e41f4b71Sopenharmony_ci console.log('popToName' + JSON.stringify(this.pageInfos), 'Return value' + JSON.stringify(this.pageInfos.popToName('pageTwo'))) 1747e41f4b71Sopenharmony_ci }) 1748e41f4b71Sopenharmony_ci Button('popToIndex', { stateEffect: true, type: ButtonType.Capsule }) 1749e41f4b71Sopenharmony_ci .width('80%') 1750e41f4b71Sopenharmony_ci .height(40) 1751e41f4b71Sopenharmony_ci .margin(20) 1752e41f4b71Sopenharmony_ci .onClick(() => { 1753e41f4b71Sopenharmony_ci this.pageInfos.popToIndex(1) // Return the navigation stack to the navigation destination page that matches the value of index. 1754e41f4b71Sopenharmony_ci console.log('popToIndex' + JSON.stringify(this.pageInfos)) 1755e41f4b71Sopenharmony_ci }) 1756e41f4b71Sopenharmony_ci Button('moveToTop', { stateEffect: true, type: ButtonType.Capsule }) 1757e41f4b71Sopenharmony_ci .width('80%') 1758e41f4b71Sopenharmony_ci .height(40) 1759e41f4b71Sopenharmony_ci .margin(20) 1760e41f4b71Sopenharmony_ci .onClick(() => { 1761e41f4b71Sopenharmony_ci this.pageInfos.moveToTop('pageTwo') // Move to the top of the navigation stack the first navigation destination page that matches the value of name. 1762e41f4b71Sopenharmony_ci console.log('moveToTop' + JSON.stringify(this.pageInfos), 'Return value' + JSON.stringify(this.pageInfos.moveToTop('pageTwo'))) 1763e41f4b71Sopenharmony_ci }) 1764e41f4b71Sopenharmony_ci Button('moveIndexToTop', { stateEffect: true, type: ButtonType.Capsule }) 1765e41f4b71Sopenharmony_ci .width('80%') 1766e41f4b71Sopenharmony_ci .height(40) 1767e41f4b71Sopenharmony_ci .margin(20) 1768e41f4b71Sopenharmony_ci .onClick(() => { 1769e41f4b71Sopenharmony_ci this.pageInfos.moveIndexToTop(1) // Move to the top of the navigation stack the navigation destination page that matches the value of index. 1770e41f4b71Sopenharmony_ci console.log('moveIndexToTop' + JSON.stringify(this.pageInfos)) 1771e41f4b71Sopenharmony_ci }) 1772e41f4b71Sopenharmony_ci Button('clear', { stateEffect: true, type: ButtonType.Capsule }) 1773e41f4b71Sopenharmony_ci .width('80%') 1774e41f4b71Sopenharmony_ci .height(40) 1775e41f4b71Sopenharmony_ci .margin(20) 1776e41f4b71Sopenharmony_ci .onClick(() => { 1777e41f4b71Sopenharmony_ci this.pageInfos.clear() // Clear the navigation stack. 1778e41f4b71Sopenharmony_ci }) 1779e41f4b71Sopenharmony_ci Button('get', { stateEffect: true, type: ButtonType.Capsule }) 1780e41f4b71Sopenharmony_ci .width('80%') 1781e41f4b71Sopenharmony_ci .height(40) 1782e41f4b71Sopenharmony_ci .margin(20) 1783e41f4b71Sopenharmony_ci .onClick(() => { 1784e41f4b71Sopenharmony_ci console.log('-------------------') 1785e41f4b71Sopenharmony_ci console.log('Obtained the names of all pages in the navigation stack', JSON.stringify(this.pageInfos.getAllPathName())) 1786e41f4b71Sopenharmony_ci console.log('Obtained parameter information of the navigation destination page specified by index', JSON.stringify(this.pageInfos.getParamByIndex(1))) 1787e41f4b71Sopenharmony_ci console.log('Obtained parameter information of all the navigation destination pages specified by name', JSON.stringify(this.pageInfos.getParamByName('pageTwo'))) 1788e41f4b71Sopenharmony_ci console.log('Obtained the index information of all the navigation destination pages specified by name', JSON.stringify(this.pageInfos.getIndexByName('pageOne')))) 1789e41f4b71Sopenharmony_ci console.log ('Obtained the stack size', JSON.stringify (this.pageInfos.size ())) 1790e41f4b71Sopenharmony_ci }) 1791e41f4b71Sopenharmony_ci }.width('100%').height('100%') 1792e41f4b71Sopenharmony_ci }.title('pageOne') 1793e41f4b71Sopenharmony_ci .onBackPressed(() => { 1794e41f4b71Sopenharmony_ci const popDestinationInfo = this.pageInfos.pop() // Pop the top element out of the navigation stack. 1795e41f4b71Sopenharmony_ci console.log('pop' + 'Return value' + JSON.stringify(popDestinationInfo)) 1796e41f4b71Sopenharmony_ci return true 1797e41f4b71Sopenharmony_ci }).onReady((context: NavDestinationContext) => { 1798e41f4b71Sopenharmony_ci this.pageInfos = context.pathStack 1799e41f4b71Sopenharmony_ci }) 1800e41f4b71Sopenharmony_ci } 1801e41f4b71Sopenharmony_ci} 1802e41f4b71Sopenharmony_ci``` 1803e41f4b71Sopenharmony_ci```ts 1804e41f4b71Sopenharmony_ci// PageTwo.ets 1805e41f4b71Sopenharmony_ci@Builder 1806e41f4b71Sopenharmony_ciexport function PageTwoBuilder(name: string, param: Object) { 1807e41f4b71Sopenharmony_ci PageTwo() 1808e41f4b71Sopenharmony_ci} 1809e41f4b71Sopenharmony_ci 1810e41f4b71Sopenharmony_ci@Component 1811e41f4b71Sopenharmony_ciexport struct PageTwo { 1812e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 1813e41f4b71Sopenharmony_ci 1814e41f4b71Sopenharmony_ci private menuItems: Array<NavigationMenuItem> = [ 1815e41f4b71Sopenharmony_ci { 1816e41f4b71Sopenharmony_ci value: "1", 1817e41f4b71Sopenharmony_ci icon: 'resources/base/media/undo.svg', 1818e41f4b71Sopenharmony_ci }, 1819e41f4b71Sopenharmony_ci { 1820e41f4b71Sopenharmony_ci value: "2", 1821e41f4b71Sopenharmony_ci icon: 'resources/base/media/redo.svg', 1822e41f4b71Sopenharmony_ci isEnabled: false, 1823e41f4b71Sopenharmony_ci }, 1824e41f4b71Sopenharmony_ci { 1825e41f4b71Sopenharmony_ci value: "3", 1826e41f4b71Sopenharmony_ci icon: 'resources/base/media/ic_public_ok.svg', 1827e41f4b71Sopenharmony_ci isEnabled: true, 1828e41f4b71Sopenharmony_ci } 1829e41f4b71Sopenharmony_ci ] 1830e41f4b71Sopenharmony_ci 1831e41f4b71Sopenharmony_ci build() { 1832e41f4b71Sopenharmony_ci NavDestination() { 1833e41f4b71Sopenharmony_ci Column() { 1834e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 1835e41f4b71Sopenharmony_ci .width('80%') 1836e41f4b71Sopenharmony_ci .height(40) 1837e41f4b71Sopenharmony_ci .margin(20) 1838e41f4b71Sopenharmony_ci .onClick(() => { 1839e41f4b71Sopenharmony_ci this.pathStack.pushPathByName('pageOne', null) 1840e41f4b71Sopenharmony_ci }) 1841e41f4b71Sopenharmony_ci }.width('100%').height('100%') 1842e41f4b71Sopenharmony_ci }.title('pageTwo') 1843e41f4b71Sopenharmony_ci .menus(this.menuItems) 1844e41f4b71Sopenharmony_ci .onBackPressed(() => { 1845e41f4b71Sopenharmony_ci this.pathStack.pop() 1846e41f4b71Sopenharmony_ci return true 1847e41f4b71Sopenharmony_ci }) 1848e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 1849e41f4b71Sopenharmony_ci this.pathStack = context.pathStack; 1850e41f4b71Sopenharmony_ci console.log("current page config info is " + JSON.stringify(context.getConfigInRouteMap())) 1851e41f4b71Sopenharmony_ci }) 1852e41f4b71Sopenharmony_ci } 1853e41f4b71Sopenharmony_ci} 1854e41f4b71Sopenharmony_ci``` 1855e41f4b71Sopenharmony_ci 1856e41f4b71Sopenharmony_ci```json 1857e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 1858e41f4b71Sopenharmony_ci// route_map.json 1859e41f4b71Sopenharmony_ci{ 1860e41f4b71Sopenharmony_ci "routerMap": [ 1861e41f4b71Sopenharmony_ci { 1862e41f4b71Sopenharmony_ci "name": "pageOne", 1863e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 1864e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 1865e41f4b71Sopenharmony_ci "data": { 1866e41f4b71Sopenharmony_ci "description": "this is pageOne" 1867e41f4b71Sopenharmony_ci } 1868e41f4b71Sopenharmony_ci }, 1869e41f4b71Sopenharmony_ci { 1870e41f4b71Sopenharmony_ci "name": "pageTwo", 1871e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageTwo.ets", 1872e41f4b71Sopenharmony_ci "buildFunction": "PageTwoBuilder" 1873e41f4b71Sopenharmony_ci } 1874e41f4b71Sopenharmony_ci ] 1875e41f4b71Sopenharmony_ci} 1876e41f4b71Sopenharmony_ci``` 1877e41f4b71Sopenharmony_ci 1878e41f4b71Sopenharmony_ci 1879e41f4b71Sopenharmony_ci### Example 3 1880e41f4b71Sopenharmony_ci 1881e41f4b71Sopenharmony_ciThis sample demonstrates how to set a custom transition animation and an interactive transition animation for each **NavDestination** page. 1882e41f4b71Sopenharmony_ci 1883e41f4b71Sopenharmony_ci```ts 1884e41f4b71Sopenharmony_ci// Index.ets 1885e41f4b71Sopenharmony_ciimport { CustomTransition, AnimateCallback } from './CustomNavigationUtils' 1886e41f4b71Sopenharmony_ci 1887e41f4b71Sopenharmony_ci@Entry 1888e41f4b71Sopenharmony_ci@Component 1889e41f4b71Sopenharmony_cistruct NavigationExample { 1890e41f4b71Sopenharmony_ci pageInfos: NavPathStack = new NavPathStack(); 1891e41f4b71Sopenharmony_ci 1892e41f4b71Sopenharmony_ci aboutToAppear() { 1893e41f4b71Sopenharmony_ci if (this.pageInfos === undefined) { 1894e41f4b71Sopenharmony_ci this.pageInfos = new NavPathStack(); 1895e41f4b71Sopenharmony_ci } 1896e41f4b71Sopenharmony_ci this.pageInfos.pushPath({ name: 'pageOne', param: CustomTransition.getInstance().getAnimationId() }); 1897e41f4b71Sopenharmony_ci } 1898e41f4b71Sopenharmony_ci 1899e41f4b71Sopenharmony_ci build() { 1900e41f4b71Sopenharmony_ci Navigation(this.pageInfos) { 1901e41f4b71Sopenharmony_ci } 1902e41f4b71Sopenharmony_ci .title('NavIndex') 1903e41f4b71Sopenharmony_ci .hideNavBar(true) 1904e41f4b71Sopenharmony_ci .customNavContentTransition((from: NavContentInfo, to: NavContentInfo, operation: NavigationOperation) => { 1905e41f4b71Sopenharmony_ci if (from.mode == NavDestinationMode.DIALOG || to.mode == NavDestinationMode.DIALOG) { 1906e41f4b71Sopenharmony_ci return undefined; 1907e41f4b71Sopenharmony_ci } 1908e41f4b71Sopenharmony_ci 1909e41f4b71Sopenharmony_ci // No custom animation for the home page 1910e41f4b71Sopenharmony_ci if (from.index === -1 || to.index === -1) { 1911e41f4b71Sopenharmony_ci return undefined; 1912e41f4b71Sopenharmony_ci } 1913e41f4b71Sopenharmony_ci 1914e41f4b71Sopenharmony_ci CustomTransition.getInstance().operation = operation; 1915e41f4b71Sopenharmony_ci if (CustomTransition.getInstance().interactive) { 1916e41f4b71Sopenharmony_ci let customAnimation: NavigationAnimatedTransition = { 1917e41f4b71Sopenharmony_ci onTransitionEnd: (isSuccess: boolean) => { 1918e41f4b71Sopenharmony_ci console.log("===== current transition is " + isSuccess); 1919e41f4b71Sopenharmony_ci CustomTransition.getInstance().recoverState(); 1920e41f4b71Sopenharmony_ci CustomTransition.getInstance().proxy = undefined; 1921e41f4b71Sopenharmony_ci }, 1922e41f4b71Sopenharmony_ci transition: (transitionProxy: NavigationTransitionProxy) => { 1923e41f4b71Sopenharmony_ci CustomTransition.getInstance().proxy = transitionProxy; 1924e41f4b71Sopenharmony_ci let targetIndex: string | undefined = operation == NavigationOperation.PUSH ? 1925e41f4b71Sopenharmony_ci (to.navDestinationId) : (from.navDestinationId); 1926e41f4b71Sopenharmony_ci if (targetIndex) { 1927e41f4b71Sopenharmony_ci CustomTransition.getInstance().fireInteractiveAnimation(targetIndex, operation); 1928e41f4b71Sopenharmony_ci } 1929e41f4b71Sopenharmony_ci }, 1930e41f4b71Sopenharmony_ci isInteractive: CustomTransition.getInstance().interactive 1931e41f4b71Sopenharmony_ci } 1932e41f4b71Sopenharmony_ci return customAnimation; 1933e41f4b71Sopenharmony_ci } 1934e41f4b71Sopenharmony_ci let customAnimation: NavigationAnimatedTransition = { 1935e41f4b71Sopenharmony_ci onTransitionEnd: (isSuccess: boolean)=>{ 1936e41f4b71Sopenharmony_ci console.log(`current transition result is ${isSuccess}`) 1937e41f4b71Sopenharmony_ci }, 1938e41f4b71Sopenharmony_ci timeout: 7000, 1939e41f4b71Sopenharmony_ci // When the transition starts, the system calls this method and passes in the transition context proxy object. 1940e41f4b71Sopenharmony_ci transition: (transitionProxy: NavigationTransitionProxy) => { 1941e41f4b71Sopenharmony_ci if (!from.navDestinationId || !to.navDestinationId) { 1942e41f4b71Sopenharmony_ci return; 1943e41f4b71Sopenharmony_ci } 1944e41f4b71Sopenharmony_ci // Obtain the corresponding transition animation callback from the CustomTransition class based on the sequence of subpages. 1945e41f4b71Sopenharmony_ci let fromParam: AnimateCallback = CustomTransition.getInstance().getAnimateParam(from.navDestinationId); 1946e41f4b71Sopenharmony_ci let toParam: AnimateCallback = CustomTransition.getInstance().getAnimateParam(to.navDestinationId); 1947e41f4b71Sopenharmony_ci if (operation == NavigationOperation.PUSH) { 1948e41f4b71Sopenharmony_ci if (toParam.start) { 1949e41f4b71Sopenharmony_ci toParam.start(true, false); 1950e41f4b71Sopenharmony_ci } 1951e41f4b71Sopenharmony_ci animateTo({ 1952e41f4b71Sopenharmony_ci duration: 500, onFinish: () => { 1953e41f4b71Sopenharmony_ci transitionProxy.finishTransition(); 1954e41f4b71Sopenharmony_ci } 1955e41f4b71Sopenharmony_ci }, () => { 1956e41f4b71Sopenharmony_ci if (toParam.finish) { 1957e41f4b71Sopenharmony_ci toParam.finish(true, false); 1958e41f4b71Sopenharmony_ci } 1959e41f4b71Sopenharmony_ci }) 1960e41f4b71Sopenharmony_ci } else { 1961e41f4b71Sopenharmony_ci if (fromParam.start) { 1962e41f4b71Sopenharmony_ci fromParam.start(true, true); 1963e41f4b71Sopenharmony_ci } 1964e41f4b71Sopenharmony_ci animateTo({ 1965e41f4b71Sopenharmony_ci duration: 500, onFinish: () => { 1966e41f4b71Sopenharmony_ci transitionProxy.finishTransition(); 1967e41f4b71Sopenharmony_ci } 1968e41f4b71Sopenharmony_ci }, () => { 1969e41f4b71Sopenharmony_ci if (fromParam.finish) { 1970e41f4b71Sopenharmony_ci fromParam.finish(true, true); 1971e41f4b71Sopenharmony_ci } 1972e41f4b71Sopenharmony_ci }) 1973e41f4b71Sopenharmony_ci } 1974e41f4b71Sopenharmony_ci } 1975e41f4b71Sopenharmony_ci }; 1976e41f4b71Sopenharmony_ci return customAnimation; 1977e41f4b71Sopenharmony_ci }) 1978e41f4b71Sopenharmony_ci } 1979e41f4b71Sopenharmony_ci} 1980e41f4b71Sopenharmony_ci``` 1981e41f4b71Sopenharmony_ci 1982e41f4b71Sopenharmony_ci```ts 1983e41f4b71Sopenharmony_ci// PageOne.ets 1984e41f4b71Sopenharmony_ciimport {CustomTransition} from './CustomNavigationUtils'; 1985e41f4b71Sopenharmony_ci 1986e41f4b71Sopenharmony_ci@Builder 1987e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 1988e41f4b71Sopenharmony_ci PageOne() 1989e41f4b71Sopenharmony_ci} 1990e41f4b71Sopenharmony_ci 1991e41f4b71Sopenharmony_ci@Component 1992e41f4b71Sopenharmony_ciexport struct PageOne { 1993e41f4b71Sopenharmony_ci pageInfos: NavPathStack = new NavPathStack(); 1994e41f4b71Sopenharmony_ci @State translateX: string = '0'; 1995e41f4b71Sopenharmony_ci pageId: string = ''; 1996e41f4b71Sopenharmony_ci rectWidth: number = 0; 1997e41f4b71Sopenharmony_ci interactive: boolean = false; 1998e41f4b71Sopenharmony_ci 1999e41f4b71Sopenharmony_ci registerCallback() { 2000e41f4b71Sopenharmony_ci CustomTransition.getInstance().registerNavParam(this.pageId, (isPush: boolean, isExit: boolean) => { 2001e41f4b71Sopenharmony_ci if (isPush) { 2002e41f4b71Sopenharmony_ci this.translateX = '100%'; 2003e41f4b71Sopenharmony_ci } else { 2004e41f4b71Sopenharmony_ci this.translateX = '0'; 2005e41f4b71Sopenharmony_ci } 2006e41f4b71Sopenharmony_ci }, (isPush: boolean, isExit: boolean) => { 2007e41f4b71Sopenharmony_ci if (isPush) { 2008e41f4b71Sopenharmony_ci this.translateX = '0'; 2009e41f4b71Sopenharmony_ci } else { 2010e41f4b71Sopenharmony_ci this.translateX = '100%'; 2011e41f4b71Sopenharmony_ci } 2012e41f4b71Sopenharmony_ci }, (isPush: boolean, isExit: boolean) => { 2013e41f4b71Sopenharmony_ci this.translateX = '0'; 2014e41f4b71Sopenharmony_ci }, (operation: NavigationOperation) => { 2015e41f4b71Sopenharmony_ci if (operation == NavigationOperation.PUSH) { 2016e41f4b71Sopenharmony_ci this.translateX = '100%'; 2017e41f4b71Sopenharmony_ci animateTo({ 2018e41f4b71Sopenharmony_ci duration: 1000, 2019e41f4b71Sopenharmony_ci onFinish: () => { 2020e41f4b71Sopenharmony_ci this.translateX = '0'; 2021e41f4b71Sopenharmony_ci } 2022e41f4b71Sopenharmony_ci }, () => { 2023e41f4b71Sopenharmony_ci this.translateX = '0'; 2024e41f4b71Sopenharmony_ci }) 2025e41f4b71Sopenharmony_ci } else { 2026e41f4b71Sopenharmony_ci this.translateX = '0'; 2027e41f4b71Sopenharmony_ci animateTo({ 2028e41f4b71Sopenharmony_ci duration: 1000, 2029e41f4b71Sopenharmony_ci onFinish: () => { 2030e41f4b71Sopenharmony_ci this.translateX = '0'; 2031e41f4b71Sopenharmony_ci } 2032e41f4b71Sopenharmony_ci }, () => { 2033e41f4b71Sopenharmony_ci this.translateX = '100%'; 2034e41f4b71Sopenharmony_ci }) 2035e41f4b71Sopenharmony_ci } 2036e41f4b71Sopenharmony_ci }, 200); 2037e41f4b71Sopenharmony_ci } 2038e41f4b71Sopenharmony_ci 2039e41f4b71Sopenharmony_ci build() { 2040e41f4b71Sopenharmony_ci NavDestination() { 2041e41f4b71Sopenharmony_ci Column() { 2042e41f4b71Sopenharmony_ci Button(`setInteractive`) 2043e41f4b71Sopenharmony_ci .onClick(() => { 2044e41f4b71Sopenharmony_ci CustomTransition.getInstance().interactive = !CustomTransition.getInstance().interactive; 2045e41f4b71Sopenharmony_ci this.interactive = CustomTransition.getInstance().interactive; 2046e41f4b71Sopenharmony_ci }) 2047e41f4b71Sopenharmony_ci 2048e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 2049e41f4b71Sopenharmony_ci .width('80%') 2050e41f4b71Sopenharmony_ci .height(40) 2051e41f4b71Sopenharmony_ci .margin(20) 2052e41f4b71Sopenharmony_ci .onClick(() => { 2053e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 2054e41f4b71Sopenharmony_ci this.pageInfos.pushDestinationByName('pageTwo', CustomTransition.getInstance().getAnimationId()); 2055e41f4b71Sopenharmony_ci }) 2056e41f4b71Sopenharmony_ci } 2057e41f4b71Sopenharmony_ci .size({ width: '100%', height: '100%' }) 2058e41f4b71Sopenharmony_ci } 2059e41f4b71Sopenharmony_ci .title('pageOne') 2060e41f4b71Sopenharmony_ci .onDisAppear(() => { 2061e41f4b71Sopenharmony_ci CustomTransition.getInstance().unRegisterNavParam(this.pageId); 2062e41f4b71Sopenharmony_ci }) 2063e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 2064e41f4b71Sopenharmony_ci this.pageInfos = context.pathStack; 2065e41f4b71Sopenharmony_ci if (context.navDestinationId) { 2066e41f4b71Sopenharmony_ci this.pageId = context.navDestinationId; 2067e41f4b71Sopenharmony_ci this.registerCallback(); 2068e41f4b71Sopenharmony_ci } 2069e41f4b71Sopenharmony_ci }) 2070e41f4b71Sopenharmony_ci .translate({ x: this.translateX }) 2071e41f4b71Sopenharmony_ci .backgroundColor('#F1F3F5') 2072e41f4b71Sopenharmony_ci .gesture(PanGesture() 2073e41f4b71Sopenharmony_ci .onActionStart((event: GestureEvent) => { 2074e41f4b71Sopenharmony_ci this.rectWidth = event.target.area.width as number; 2075e41f4b71Sopenharmony_ci if (event.offsetX < 0) { 2076e41f4b71Sopenharmony_ci this.pageInfos.pushPath({ name: 'pageTwo', param: CustomTransition.getInstance().getAnimationId() }); 2077e41f4b71Sopenharmony_ci } else { 2078e41f4b71Sopenharmony_ci this.pageInfos.pop(); 2079e41f4b71Sopenharmony_ci } 2080e41f4b71Sopenharmony_ci }) 2081e41f4b71Sopenharmony_ci .onActionUpdate((event: GestureEvent) => { 2082e41f4b71Sopenharmony_ci let rate = event.fingerList[0].localX / this.rectWidth; 2083e41f4b71Sopenharmony_ci CustomTransition.getInstance().updateProgress(rate); 2084e41f4b71Sopenharmony_ci }) 2085e41f4b71Sopenharmony_ci .onActionEnd((event: GestureEvent) => { 2086e41f4b71Sopenharmony_ci let rate: number = event.fingerList[0].localX / this.rectWidth; 2087e41f4b71Sopenharmony_ci CustomTransition.getInstance().finishInteractiveAnimation(rate); 2088e41f4b71Sopenharmony_ci })) 2089e41f4b71Sopenharmony_ci } 2090e41f4b71Sopenharmony_ci} 2091e41f4b71Sopenharmony_ci``` 2092e41f4b71Sopenharmony_ci```ts 2093e41f4b71Sopenharmony_ci// PageTwo.ets 2094e41f4b71Sopenharmony_ciimport {CustomTransition} from './CustomNavigationUtils' 2095e41f4b71Sopenharmony_ci 2096e41f4b71Sopenharmony_ci@Builder 2097e41f4b71Sopenharmony_ciexport function PageTwoBuilder(name: string, param: Object) { 2098e41f4b71Sopenharmony_ci PageTwo({param: param as number}) 2099e41f4b71Sopenharmony_ci} 2100e41f4b71Sopenharmony_ci 2101e41f4b71Sopenharmony_ci@Component 2102e41f4b71Sopenharmony_ciexport struct PageTwo { 2103e41f4b71Sopenharmony_ci pageInfos: NavPathStack = new NavPathStack(); 2104e41f4b71Sopenharmony_ci @State translateX: string = '0'; 2105e41f4b71Sopenharmony_ci pageId: string = ''; 2106e41f4b71Sopenharmony_ci rectWidth: number = 0; 2107e41f4b71Sopenharmony_ci param: number = 0; 2108e41f4b71Sopenharmony_ci 2109e41f4b71Sopenharmony_ci registerCallback() { 2110e41f4b71Sopenharmony_ci CustomTransition.getInstance().registerNavParam(this.pageId, (isPush: boolean, isExit: boolean)=>{ 2111e41f4b71Sopenharmony_ci if (isPush) { 2112e41f4b71Sopenharmony_ci this.translateX = '100%' 2113e41f4b71Sopenharmony_ci } else { 2114e41f4b71Sopenharmony_ci this.translateX = '0'; 2115e41f4b71Sopenharmony_ci } 2116e41f4b71Sopenharmony_ci }, (isPush: boolean, isExit: boolean)=>{ 2117e41f4b71Sopenharmony_ci if (isPush) { 2118e41f4b71Sopenharmony_ci this.translateX = '0'; 2119e41f4b71Sopenharmony_ci } else { 2120e41f4b71Sopenharmony_ci this.translateX = '100%' 2121e41f4b71Sopenharmony_ci } 2122e41f4b71Sopenharmony_ci }, (isPush: boolean, isExit: boolean) => { 2123e41f4b71Sopenharmony_ci this.translateX = '0'; 2124e41f4b71Sopenharmony_ci }, (operation: NavigationOperation)=>{ 2125e41f4b71Sopenharmony_ci if (operation == NavigationOperation.PUSH) { 2126e41f4b71Sopenharmony_ci this.translateX = '100%'; 2127e41f4b71Sopenharmony_ci animateTo({duration: 500, onFinish: ()=>{ 2128e41f4b71Sopenharmony_ci this.translateX = '0'; 2129e41f4b71Sopenharmony_ci }}, ()=>{ 2130e41f4b71Sopenharmony_ci this.translateX = '0' 2131e41f4b71Sopenharmony_ci }) 2132e41f4b71Sopenharmony_ci } else { 2133e41f4b71Sopenharmony_ci this.translateX = '0'; 2134e41f4b71Sopenharmony_ci animateTo({duration: 500, onFinish: ()=>{ 2135e41f4b71Sopenharmony_ci this.translateX = "0" 2136e41f4b71Sopenharmony_ci }}, ()=>{ 2137e41f4b71Sopenharmony_ci this.translateX = '100%'; 2138e41f4b71Sopenharmony_ci }) 2139e41f4b71Sopenharmony_ci } 2140e41f4b71Sopenharmony_ci }, 2000) 2141e41f4b71Sopenharmony_ci } 2142e41f4b71Sopenharmony_ci 2143e41f4b71Sopenharmony_ci build() { 2144e41f4b71Sopenharmony_ci NavDestination() { 2145e41f4b71Sopenharmony_ci Column() { 2146e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 2147e41f4b71Sopenharmony_ci .width('80%') 2148e41f4b71Sopenharmony_ci .height(40) 2149e41f4b71Sopenharmony_ci .margin(20) 2150e41f4b71Sopenharmony_ci .onClick(() => { 2151e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 2152e41f4b71Sopenharmony_ci this.pageInfos.pushPath({name:'pageOne', param: CustomTransition.getInstance().getAnimationId()}) 2153e41f4b71Sopenharmony_ci }) 2154e41f4b71Sopenharmony_ci } 2155e41f4b71Sopenharmony_ci .size({ width: '100%', height: '100%' }) 2156e41f4b71Sopenharmony_ci } 2157e41f4b71Sopenharmony_ci .title('pageTwo') 2158e41f4b71Sopenharmony_ci .gesture(PanGesture() 2159e41f4b71Sopenharmony_ci .onActionStart((event: GestureEvent)=> { 2160e41f4b71Sopenharmony_ci this.rectWidth = event.target.area.width as number; 2161e41f4b71Sopenharmony_ci if (event.offsetX < 0) { 2162e41f4b71Sopenharmony_ci this.pageInfos.pushPath({ name: 'pageOne', param: CustomTransition.getInstance().getAnimationId() }); 2163e41f4b71Sopenharmony_ci } else { 2164e41f4b71Sopenharmony_ci this.pageInfos.pop(); 2165e41f4b71Sopenharmony_ci } 2166e41f4b71Sopenharmony_ci }) 2167e41f4b71Sopenharmony_ci .onActionUpdate((event: GestureEvent) => { 2168e41f4b71Sopenharmony_ci let rate = event.fingerList[0].localX / this.rectWidth; 2169e41f4b71Sopenharmony_ci CustomTransition.getInstance().updateProgress(rate); 2170e41f4b71Sopenharmony_ci }) 2171e41f4b71Sopenharmony_ci .onActionEnd((event: GestureEvent)=> { 2172e41f4b71Sopenharmony_ci let rate = event.fingerList[0].localX / this.rectWidth; 2173e41f4b71Sopenharmony_ci CustomTransition.getInstance().finishInteractiveAnimation(rate); 2174e41f4b71Sopenharmony_ci })) 2175e41f4b71Sopenharmony_ci .onAppear(() => { 2176e41f4b71Sopenharmony_ci this.registerCallback(); 2177e41f4b71Sopenharmony_ci }) 2178e41f4b71Sopenharmony_ci .onDisAppear(()=>{ 2179e41f4b71Sopenharmony_ci CustomTransition.getInstance().unRegisterNavParam(this.pageId); 2180e41f4b71Sopenharmony_ci }) 2181e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 2182e41f4b71Sopenharmony_ci this.pageInfos = context.pathStack; 2183e41f4b71Sopenharmony_ci if (context.navDestinationId) { 2184e41f4b71Sopenharmony_ci this.pageId = context.navDestinationId; 2185e41f4b71Sopenharmony_ci this.registerCallback(); 2186e41f4b71Sopenharmony_ci } 2187e41f4b71Sopenharmony_ci }) 2188e41f4b71Sopenharmony_ci .translate({x: this.translateX}) 2189e41f4b71Sopenharmony_ci .backgroundColor(Color.Yellow) 2190e41f4b71Sopenharmony_ci } 2191e41f4b71Sopenharmony_ci} 2192e41f4b71Sopenharmony_ci``` 2193e41f4b71Sopenharmony_ci```ts 2194e41f4b71Sopenharmony_ci// CustomNavigationUtils.ts 2195e41f4b71Sopenharmony_ci// Custom API to save the transition animation callback and parameters related to a page. 2196e41f4b71Sopenharmony_ciexport interface AnimateCallback { 2197e41f4b71Sopenharmony_ci finish: ((isPush: boolean, isExit: boolean) => void | undefined) | undefined; 2198e41f4b71Sopenharmony_ci start: ((isPush: boolean, isExit: boolean) => void | undefined) | undefined; 2199e41f4b71Sopenharmony_ci onFinish: ((isPush: boolean, isExit: boolean) => void | undefined) | undefined; 2200e41f4b71Sopenharmony_ci interactive: ((operation: NavigationOperation) => void | undefined) | undefined; 2201e41f4b71Sopenharmony_ci timeout: (number | undefined) | undefined; 2202e41f4b71Sopenharmony_ci} 2203e41f4b71Sopenharmony_ciconst customTransitionMap: Map<string, AnimateCallback> = new Map(); 2204e41f4b71Sopenharmony_ci 2205e41f4b71Sopenharmony_ciexport class CustomTransition { 2206e41f4b71Sopenharmony_ci static delegate = new CustomTransition(); 2207e41f4b71Sopenharmony_ci interactive: boolean = false; 2208e41f4b71Sopenharmony_ci proxy: NavigationTransitionProxy| undefined = undefined; 2209e41f4b71Sopenharmony_ci private animationId: number = 0; 2210e41f4b71Sopenharmony_ci operation: NavigationOperation = NavigationOperation.PUSH 2211e41f4b71Sopenharmony_ci 2212e41f4b71Sopenharmony_ci static getInstance() { 2213e41f4b71Sopenharmony_ci return CustomTransition.delegate; 2214e41f4b71Sopenharmony_ci } 2215e41f4b71Sopenharmony_ci 2216e41f4b71Sopenharmony_ci /* Register animation callbacks for a page. 2217e41f4b71Sopenharmony_ci * name: unique ID of the target page 2218e41f4b71Sopenharmony_ci * startCallback: used to set the page state at the start of the animation. 2219e41f4b71Sopenharmony_ci * endCallback: used to set the page state at the end of the animation. 2220e41f4b71Sopenharmony_ci * onFinish: used to perform other operations after the animation ends. 2221e41f4b71Sopenharmony_ci * interactiveCallback: used to handle the interactive part of the transition. 2222e41f4b71Sopenharmony_ci * timeout: timeout for ending the transition. 2223e41f4b71Sopenharmony_ci */ 2224e41f4b71Sopenharmony_ci registerNavParam(name: string, startCallback: (operation: boolean, isExit: boolean) => void, 2225e41f4b71Sopenharmony_ci endCallback:(operation: boolean, isExit: boolean) => void, 2226e41f4b71Sopenharmony_ci onFinish: (operation: boolean, isExit: boolean) => void, 2227e41f4b71Sopenharmony_ci interactiveCallback: (operation: NavigationOperation) =>void, 2228e41f4b71Sopenharmony_ci timeout: number): void { 2229e41f4b71Sopenharmony_ci if (customTransitionMap.has(name)) { 2230e41f4b71Sopenharmony_ci let param = customTransitionMap.get(name); 2231e41f4b71Sopenharmony_ci if (param != undefined) { 2232e41f4b71Sopenharmony_ci param.start = startCallback; 2233e41f4b71Sopenharmony_ci param.finish = endCallback; 2234e41f4b71Sopenharmony_ci param.timeout = timeout; 2235e41f4b71Sopenharmony_ci param.onFinish = onFinish; 2236e41f4b71Sopenharmony_ci param.interactive = interactiveCallback; 2237e41f4b71Sopenharmony_ci return; 2238e41f4b71Sopenharmony_ci } 2239e41f4b71Sopenharmony_ci } 2240e41f4b71Sopenharmony_ci let params: AnimateCallback = {timeout: timeout, start: startCallback, finish: endCallback, onFinish: onFinish, 2241e41f4b71Sopenharmony_ci interactive: interactiveCallback}; 2242e41f4b71Sopenharmony_ci customTransitionMap.set(name, params); 2243e41f4b71Sopenharmony_ci } 2244e41f4b71Sopenharmony_ci 2245e41f4b71Sopenharmony_ci getAnimationId() { 2246e41f4b71Sopenharmony_ci return Date.now(); 2247e41f4b71Sopenharmony_ci } 2248e41f4b71Sopenharmony_ci 2249e41f4b71Sopenharmony_ci unRegisterNavParam(name: string): void { 2250e41f4b71Sopenharmony_ci customTransitionMap.delete(name); 2251e41f4b71Sopenharmony_ci } 2252e41f4b71Sopenharmony_ci 2253e41f4b71Sopenharmony_ci fireInteractiveAnimation(id: string, operation: NavigationOperation) { 2254e41f4b71Sopenharmony_ci let animation = customTransitionMap.get(id)?.interactive; 2255e41f4b71Sopenharmony_ci if (!animation) { 2256e41f4b71Sopenharmony_ci return; 2257e41f4b71Sopenharmony_ci } 2258e41f4b71Sopenharmony_ci animation(operation); 2259e41f4b71Sopenharmony_ci } 2260e41f4b71Sopenharmony_ci 2261e41f4b71Sopenharmony_ci updateProgress(progress: number) { 2262e41f4b71Sopenharmony_ci if (!this.proxy?.updateTransition) { 2263e41f4b71Sopenharmony_ci return; 2264e41f4b71Sopenharmony_ci } 2265e41f4b71Sopenharmony_ci progress = this.operation == NavigationOperation.PUSH ? 1 - progress : progress; 2266e41f4b71Sopenharmony_ci this.proxy?.updateTransition(progress); 2267e41f4b71Sopenharmony_ci } 2268e41f4b71Sopenharmony_ci 2269e41f4b71Sopenharmony_ci cancelTransition() { 2270e41f4b71Sopenharmony_ci if (this.proxy?.cancelTransition) { 2271e41f4b71Sopenharmony_ci this.proxy.cancelTransition(); 2272e41f4b71Sopenharmony_ci } 2273e41f4b71Sopenharmony_ci } 2274e41f4b71Sopenharmony_ci 2275e41f4b71Sopenharmony_ci recoverState() { 2276e41f4b71Sopenharmony_ci if (!this.proxy?.from.navDestinationId || !this.proxy?.to.navDestinationId) { 2277e41f4b71Sopenharmony_ci return; 2278e41f4b71Sopenharmony_ci } 2279e41f4b71Sopenharmony_ci let fromParam = customTransitionMap.get(this.proxy.from.navDestinationId); 2280e41f4b71Sopenharmony_ci if (fromParam?.onFinish) { 2281e41f4b71Sopenharmony_ci fromParam.onFinish(false, false); 2282e41f4b71Sopenharmony_ci } 2283e41f4b71Sopenharmony_ci let toParam = customTransitionMap.get(this.proxy?.to.navDestinationId); 2284e41f4b71Sopenharmony_ci if (toParam?.onFinish) { 2285e41f4b71Sopenharmony_ci toParam.onFinish(true, true); 2286e41f4b71Sopenharmony_ci } 2287e41f4b71Sopenharmony_ci } 2288e41f4b71Sopenharmony_ci 2289e41f4b71Sopenharmony_ci finishTransition() { 2290e41f4b71Sopenharmony_ci this.proxy?.finishTransition(); 2291e41f4b71Sopenharmony_ci } 2292e41f4b71Sopenharmony_ci 2293e41f4b71Sopenharmony_ci finishInteractiveAnimation(rate: number) { 2294e41f4b71Sopenharmony_ci if (this.operation == NavigationOperation.PUSH) { 2295e41f4b71Sopenharmony_ci if (rate > 0.5) { 2296e41f4b71Sopenharmony_ci if (this.proxy?.cancelTransition) { 2297e41f4b71Sopenharmony_ci this.proxy.cancelTransition(); 2298e41f4b71Sopenharmony_ci } 2299e41f4b71Sopenharmony_ci } else { 2300e41f4b71Sopenharmony_ci this.proxy?.finishTransition(); 2301e41f4b71Sopenharmony_ci } 2302e41f4b71Sopenharmony_ci } else { 2303e41f4b71Sopenharmony_ci if (rate > 0.5) { 2304e41f4b71Sopenharmony_ci this.proxy?.finishTransition(); 2305e41f4b71Sopenharmony_ci } else { 2306e41f4b71Sopenharmony_ci if (this.proxy?.cancelTransition) { 2307e41f4b71Sopenharmony_ci this.proxy.cancelTransition(); 2308e41f4b71Sopenharmony_ci } 2309e41f4b71Sopenharmony_ci } 2310e41f4b71Sopenharmony_ci } 2311e41f4b71Sopenharmony_ci } 2312e41f4b71Sopenharmony_ci 2313e41f4b71Sopenharmony_ci getAnimateParam(name: string): AnimateCallback { 2314e41f4b71Sopenharmony_ci let result: AnimateCallback = { 2315e41f4b71Sopenharmony_ci start: customTransitionMap.get(name)?.start, 2316e41f4b71Sopenharmony_ci finish: customTransitionMap.get(name)?.finish, 2317e41f4b71Sopenharmony_ci timeout: customTransitionMap.get(name)?.timeout, 2318e41f4b71Sopenharmony_ci onFinish: customTransitionMap.get(name)?.onFinish, 2319e41f4b71Sopenharmony_ci interactive: customTransitionMap.get(name)?.interactive, 2320e41f4b71Sopenharmony_ci }; 2321e41f4b71Sopenharmony_ci return result; 2322e41f4b71Sopenharmony_ci } 2323e41f4b71Sopenharmony_ci} 2324e41f4b71Sopenharmony_ci``` 2325e41f4b71Sopenharmony_ci```json 2326e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 2327e41f4b71Sopenharmony_ci// route_map.json 2328e41f4b71Sopenharmony_ci{ 2329e41f4b71Sopenharmony_ci "routerMap": [ 2330e41f4b71Sopenharmony_ci { 2331e41f4b71Sopenharmony_ci "name": "pageOne", 2332e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 2333e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 2334e41f4b71Sopenharmony_ci "data": { 2335e41f4b71Sopenharmony_ci "description": "this is pageOne" 2336e41f4b71Sopenharmony_ci } 2337e41f4b71Sopenharmony_ci }, 2338e41f4b71Sopenharmony_ci { 2339e41f4b71Sopenharmony_ci "name": "pageTwo", 2340e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageTwo.ets", 2341e41f4b71Sopenharmony_ci "buildFunction": "PageTwoBuilder" 2342e41f4b71Sopenharmony_ci } 2343e41f4b71Sopenharmony_ci ] 2344e41f4b71Sopenharmony_ci} 2345e41f4b71Sopenharmony_ci``` 2346e41f4b71Sopenharmony_ci 2347e41f4b71Sopenharmony_ci 2348e41f4b71Sopenharmony_ci### Example 4 2349e41f4b71Sopenharmony_ci 2350e41f4b71Sopenharmony_ciThis example primarily demonstrates how to use **Navigation** to return to the previous page with parameters. 2351e41f4b71Sopenharmony_ci 2352e41f4b71Sopenharmony_ci```ts 2353e41f4b71Sopenharmony_ci// Index.ets 2354e41f4b71Sopenharmony_ci 2355e41f4b71Sopenharmony_ci@Entry 2356e41f4b71Sopenharmony_ci@Component 2357e41f4b71Sopenharmony_cistruct NavigationExample { 2358e41f4b71Sopenharmony_ci pageInfo: NavPathStack = new NavPathStack() 2359e41f4b71Sopenharmony_ci 2360e41f4b71Sopenharmony_ci build() { 2361e41f4b71Sopenharmony_ci Navigation(this.pageInfo) { 2362e41f4b71Sopenharmony_ci Column() { 2363e41f4b71Sopenharmony_ci Button('StartTest', { stateEffect: true, type: ButtonType.Capsule }) 2364e41f4b71Sopenharmony_ci .width('80%') 2365e41f4b71Sopenharmony_ci .height(40) 2366e41f4b71Sopenharmony_ci .margin(20) 2367e41f4b71Sopenharmony_ci .onClick(() => { 2368e41f4b71Sopenharmony_ci this.pageInfo.pushPath({ name: 'pageOne' }); // Push the navigation destination page specified by name to the navigation stack. 2369e41f4b71Sopenharmony_ci }) 2370e41f4b71Sopenharmony_ci } 2371e41f4b71Sopenharmony_ci }.title('NavIndex') 2372e41f4b71Sopenharmony_ci } 2373e41f4b71Sopenharmony_ci} 2374e41f4b71Sopenharmony_ci``` 2375e41f4b71Sopenharmony_ci```ts 2376e41f4b71Sopenharmony_ci// PageOne.ets 2377e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2378e41f4b71Sopenharmony_ci 2379e41f4b71Sopenharmony_ciclass TmpClass{ 2380e41f4b71Sopenharmony_ci count:number = 10 2381e41f4b71Sopenharmony_ci} 2382e41f4b71Sopenharmony_ci 2383e41f4b71Sopenharmony_ciclass ParamWithOp { 2384e41f4b71Sopenharmony_ci operation: number = 1 2385e41f4b71Sopenharmony_ci count: number = 10 2386e41f4b71Sopenharmony_ci} 2387e41f4b71Sopenharmony_ci 2388e41f4b71Sopenharmony_ci@Builder 2389e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 2390e41f4b71Sopenharmony_ci PageOne() 2391e41f4b71Sopenharmony_ci} 2392e41f4b71Sopenharmony_ci 2393e41f4b71Sopenharmony_ci@Component 2394e41f4b71Sopenharmony_ciexport struct PageOne { 2395e41f4b71Sopenharmony_ci pageInfo: NavPathStack = new NavPathStack(); 2396e41f4b71Sopenharmony_ci @State message: string = 'Hello World' 2397e41f4b71Sopenharmony_ci 2398e41f4b71Sopenharmony_ci build() { 2399e41f4b71Sopenharmony_ci NavDestination() { 2400e41f4b71Sopenharmony_ci Column() { 2401e41f4b71Sopenharmony_ci Text(this.message) 2402e41f4b71Sopenharmony_ci .width('80%') 2403e41f4b71Sopenharmony_ci .height(50) 2404e41f4b71Sopenharmony_ci .margin(10) 2405e41f4b71Sopenharmony_ci 2406e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 2407e41f4b71Sopenharmony_ci .width('80%') 2408e41f4b71Sopenharmony_ci .height(40) 2409e41f4b71Sopenharmony_ci .margin(10) 2410e41f4b71Sopenharmony_ci .onClick(()=>{ 2411e41f4b71Sopenharmony_ci this.pageInfo.pushPath({name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo)=>{ 2412e41f4b71Sopenharmony_ci this.message = '[pushPath]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 2413e41f4b71Sopenharmony_ci }}); // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. Use the onPop callback to receive the page processing result. 2414e41f4b71Sopenharmony_ci }) 2415e41f4b71Sopenharmony_ci 2416e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 2417e41f4b71Sopenharmony_ci .width('80%') 2418e41f4b71Sopenharmony_ci .height(40) 2419e41f4b71Sopenharmony_ci .margin(10) 2420e41f4b71Sopenharmony_ci .onClick(() => { 2421e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2422e41f4b71Sopenharmony_ci this.pageInfo.pushPathByName('pageTwo', tmp, (popInfo)=>{ 2423e41f4b71Sopenharmony_ci this.message = '[pushPathByName]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 2424e41f4b71Sopenharmony_ci }); // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. Use the onPop callback to receive the page processing result. 2425e41f4b71Sopenharmony_ci }) 2426e41f4b71Sopenharmony_ci 2427e41f4b71Sopenharmony_ci Button('pushDestination', { stateEffect: true, type: ButtonType.Capsule }) 2428e41f4b71Sopenharmony_ci .width('80%') 2429e41f4b71Sopenharmony_ci .height(40) 2430e41f4b71Sopenharmony_ci .margin(10) 2431e41f4b71Sopenharmony_ci .onClick(()=>{ 2432e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2433e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. Use the onPop callback to receive the page processing result. 2434e41f4b71Sopenharmony_ci this.pageInfo.pushDestination({name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo)=>{ 2435e41f4b71Sopenharmony_ci this.message = '[pushDestination]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 2436e41f4b71Sopenharmony_ci }}).catch((error: BusinessError)=>{ 2437e41f4b71Sopenharmony_ci console.error(`[pushDestination]failed, error code = ${error.code}, error.message = ${error.message}.`); 2438e41f4b71Sopenharmony_ci }).then(()=>{ 2439e41f4b71Sopenharmony_ci console.error('[pushDestination]success.'); 2440e41f4b71Sopenharmony_ci }); 2441e41f4b71Sopenharmony_ci }) 2442e41f4b71Sopenharmony_ci 2443e41f4b71Sopenharmony_ci Button('pushDestinationByName', { stateEffect: true, type: ButtonType.Capsule }) 2444e41f4b71Sopenharmony_ci .width('80%') 2445e41f4b71Sopenharmony_ci .height(40) 2446e41f4b71Sopenharmony_ci .margin(10) 2447e41f4b71Sopenharmony_ci .onClick(()=>{ 2448e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2449e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. Use the onPop callback to receive the page processing result. 2450e41f4b71Sopenharmony_ci this.pageInfo.pushDestinationByName('pageTwo', tmp, (popInfo)=>{ 2451e41f4b71Sopenharmony_ci this.message = '[pushDestinationByName]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 2452e41f4b71Sopenharmony_ci }).catch((error: BusinessError)=>{ 2453e41f4b71Sopenharmony_ci console.error(`[pushDestinationByName]failed, error code = ${error.code}, error.message = ${error.message}.`); 2454e41f4b71Sopenharmony_ci }).then(()=>{ 2455e41f4b71Sopenharmony_ci console.error('[pushDestinationByName]success.'); 2456e41f4b71Sopenharmony_ci }); 2457e41f4b71Sopenharmony_ci }) 2458e41f4b71Sopenharmony_ci 2459e41f4b71Sopenharmony_ci Button('pushPathWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 2460e41f4b71Sopenharmony_ci .width('80%') 2461e41f4b71Sopenharmony_ci .height(40) 2462e41f4b71Sopenharmony_ci .margin(10) 2463e41f4b71Sopenharmony_ci .onClick(()=>{ 2464e41f4b71Sopenharmony_ci this.pageInfo.pushPath({name: 'pageTwo', param: new ParamWithOp()}); // Push the navigation destination page specified by name to the navigation stack. 2465e41f4b71Sopenharmony_ci }) 2466e41f4b71Sopenharmony_ci 2467e41f4b71Sopenharmony_ci Button('pushPathByNameWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 2468e41f4b71Sopenharmony_ci .width('80%') 2469e41f4b71Sopenharmony_ci .height(40) 2470e41f4b71Sopenharmony_ci .margin(10) 2471e41f4b71Sopenharmony_ci .onClick(() => { 2472e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2473e41f4b71Sopenharmony_ci this.pageInfo.pushPathByName('pageTwo', tmp); // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 2474e41f4b71Sopenharmony_ci }) 2475e41f4b71Sopenharmony_ci 2476e41f4b71Sopenharmony_ci Button('pushDestinationWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 2477e41f4b71Sopenharmony_ci .width('80%') 2478e41f4b71Sopenharmony_ci .height(40) 2479e41f4b71Sopenharmony_ci .margin(10) 2480e41f4b71Sopenharmony_ci .onClick(()=>{ 2481e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2482e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. Use the onPop callback to receive the page processing result. 2483e41f4b71Sopenharmony_ci this.pageInfo.pushDestination({name: 'pageTwo', param: new ParamWithOp()}) 2484e41f4b71Sopenharmony_ci .catch((error: BusinessError)=>{ 2485e41f4b71Sopenharmony_ci console.error(`[pushDestinationWithoutOnPop]failed, error code = ${error.code}, error.message = ${error.message}.`); 2486e41f4b71Sopenharmony_ci }).then(()=>{ 2487e41f4b71Sopenharmony_ci console.error('[pushDestinationWithoutOnPop]success.'); 2488e41f4b71Sopenharmony_ci }); 2489e41f4b71Sopenharmony_ci }) 2490e41f4b71Sopenharmony_ci 2491e41f4b71Sopenharmony_ci Button('pushDestinationByNameWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 2492e41f4b71Sopenharmony_ci .width('80%') 2493e41f4b71Sopenharmony_ci .height(40) 2494e41f4b71Sopenharmony_ci .margin(10) 2495e41f4b71Sopenharmony_ci .onClick(() => { 2496e41f4b71Sopenharmony_ci let tmp = new TmpClass() 2497e41f4b71Sopenharmony_ci // Push the navigation destination page specified by name, with the data specified by param, to the navigation stack. 2498e41f4b71Sopenharmony_ci this.pageInfo.pushDestinationByName('pageTwo', tmp) 2499e41f4b71Sopenharmony_ci .catch((error: BusinessError)=>{ 2500e41f4b71Sopenharmony_ci console.error(`[pushDestinationByNameWithoutOnPop]failed, error code = ${error.code}, error.message = ${error.message}.`); 2501e41f4b71Sopenharmony_ci }).then(()=>{ 2502e41f4b71Sopenharmony_ci console.error('[pushDestinationByNameWithoutOnPop]success.'); 2503e41f4b71Sopenharmony_ci }); 2504e41f4b71Sopenharmony_ci }) 2505e41f4b71Sopenharmony_ci 2506e41f4b71Sopenharmony_ci Button('clear', { stateEffect: true, type: ButtonType.Capsule }) 2507e41f4b71Sopenharmony_ci .width('80%') 2508e41f4b71Sopenharmony_ci .height(40) 2509e41f4b71Sopenharmony_ci .margin(10) 2510e41f4b71Sopenharmony_ci .onClick(() => { 2511e41f4b71Sopenharmony_ci this.pageInfo.clear(); // Clear the navigation stack. 2512e41f4b71Sopenharmony_ci }) 2513e41f4b71Sopenharmony_ci }.width('100%').height('100%') 2514e41f4b71Sopenharmony_ci }.title('pageOne') 2515e41f4b71Sopenharmony_ci .onBackPressed(() => { 2516e41f4b71Sopenharmony_ci this.pageInfo.pop({number: 1}) // Pop the top element out of the navigation stack. 2517e41f4b71Sopenharmony_ci return true 2518e41f4b71Sopenharmony_ci }).onReady((context: NavDestinationContext) => { 2519e41f4b71Sopenharmony_ci this.pageInfo = context.pathStack; 2520e41f4b71Sopenharmony_ci }) 2521e41f4b71Sopenharmony_ci } 2522e41f4b71Sopenharmony_ci} 2523e41f4b71Sopenharmony_ci``` 2524e41f4b71Sopenharmony_ci```ts 2525e41f4b71Sopenharmony_ci// PageTwo.ets 2526e41f4b71Sopenharmony_ci 2527e41f4b71Sopenharmony_ciclass resultClass { 2528e41f4b71Sopenharmony_ci constructor(count: number) { 2529e41f4b71Sopenharmony_ci this.count = count; 2530e41f4b71Sopenharmony_ci } 2531e41f4b71Sopenharmony_ci count: number = 10 2532e41f4b71Sopenharmony_ci} 2533e41f4b71Sopenharmony_ci 2534e41f4b71Sopenharmony_ci@Builder 2535e41f4b71Sopenharmony_ciexport function PageTwoBuilder() { 2536e41f4b71Sopenharmony_ci PageTwo() 2537e41f4b71Sopenharmony_ci} 2538e41f4b71Sopenharmony_ci 2539e41f4b71Sopenharmony_ci@Component 2540e41f4b71Sopenharmony_ciexport struct PageTwo { 2541e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 2542e41f4b71Sopenharmony_ci 2543e41f4b71Sopenharmony_ci build() { 2544e41f4b71Sopenharmony_ci NavDestination() { 2545e41f4b71Sopenharmony_ci Column() { 2546e41f4b71Sopenharmony_ci Button('pop', { stateEffect: true, type: ButtonType.Capsule }) 2547e41f4b71Sopenharmony_ci .width('80%') 2548e41f4b71Sopenharmony_ci .height(40) 2549e41f4b71Sopenharmony_ci .margin(20) 2550e41f4b71Sopenharmony_ci .onClick(() => { 2551e41f4b71Sopenharmony_ci this.pathStack.pop(new resultClass(1)); // Return to the previous page and pass in the processing result to the onPop callback of push. 2552e41f4b71Sopenharmony_ci }) 2553e41f4b71Sopenharmony_ci 2554e41f4b71Sopenharmony_ci Button('popToName', { stateEffect: true, type: ButtonType.Capsule }) 2555e41f4b71Sopenharmony_ci .width('80%') 2556e41f4b71Sopenharmony_ci .height(40) 2557e41f4b71Sopenharmony_ci .margin(20) 2558e41f4b71Sopenharmony_ci .onClick(() => { 2559e41f4b71Sopenharmony_ci this.pathStack.popToName('pageOne', new resultClass(11)); // Move the first navigation destination page that matches name to the top of the navigation stack, and pass in the processing result to the onPop callback of push. 2560e41f4b71Sopenharmony_ci }) 2561e41f4b71Sopenharmony_ci 2562e41f4b71Sopenharmony_ci Button('popToIndex', { stateEffect: true, type: ButtonType.Capsule }) 2563e41f4b71Sopenharmony_ci .width('80%') 2564e41f4b71Sopenharmony_ci .height(40) 2565e41f4b71Sopenharmony_ci .margin(20) 2566e41f4b71Sopenharmony_ci .onClick(() => { 2567e41f4b71Sopenharmony_ci this.pathStack.popToIndex(0, new resultClass(111)); // Move the navigation destination page specified by index to the top of the navigation stack, and pass in the processing result to the onPop callback of push. 2568e41f4b71Sopenharmony_ci }) 2569e41f4b71Sopenharmony_ci 2570e41f4b71Sopenharmony_ci Button('popWithoutResult', { stateEffect: true, type: ButtonType.Capsule }) 2571e41f4b71Sopenharmony_ci .width('80%') 2572e41f4b71Sopenharmony_ci .height(40) 2573e41f4b71Sopenharmony_ci .margin(20) 2574e41f4b71Sopenharmony_ci .onClick(() => { 2575e41f4b71Sopenharmony_ci this.pathStack.pop(); 2576e41f4b71Sopenharmony_ci }) 2577e41f4b71Sopenharmony_ci 2578e41f4b71Sopenharmony_ci Button('popToNameWithoutResult', { stateEffect: true, type: ButtonType.Capsule }) 2579e41f4b71Sopenharmony_ci .width('80%') 2580e41f4b71Sopenharmony_ci .height(40) 2581e41f4b71Sopenharmony_ci .margin(20) 2582e41f4b71Sopenharmony_ci .onClick(() => { 2583e41f4b71Sopenharmony_ci this.pathStack.popToName('pageOne'); 2584e41f4b71Sopenharmony_ci }) 2585e41f4b71Sopenharmony_ci 2586e41f4b71Sopenharmony_ci Button('popToIndexWithoutResult', { stateEffect: true, type: ButtonType.Capsule }) 2587e41f4b71Sopenharmony_ci .width('80%') 2588e41f4b71Sopenharmony_ci .height(40) 2589e41f4b71Sopenharmony_ci .margin(20) 2590e41f4b71Sopenharmony_ci .onClick(() => { 2591e41f4b71Sopenharmony_ci this.pathStack.popToIndex(0); 2592e41f4b71Sopenharmony_ci }) 2593e41f4b71Sopenharmony_ci }.width('100%').height('100%') 2594e41f4b71Sopenharmony_ci }.title('pageTwo') 2595e41f4b71Sopenharmony_ci .onBackPressed(() => { 2596e41f4b71Sopenharmony_ci this.pathStack.pop(new resultClass(0)); // Return to the previous page and pass in the processing result to the onPop callback of push. 2597e41f4b71Sopenharmony_ci return true; 2598e41f4b71Sopenharmony_ci }).onReady((context: NavDestinationContext) => { 2599e41f4b71Sopenharmony_ci this.pathStack = context.pathStack 2600e41f4b71Sopenharmony_ci }) 2601e41f4b71Sopenharmony_ci } 2602e41f4b71Sopenharmony_ci} 2603e41f4b71Sopenharmony_ci``` 2604e41f4b71Sopenharmony_ci```json 2605e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 2606e41f4b71Sopenharmony_ci// route_map.json 2607e41f4b71Sopenharmony_ci{ 2608e41f4b71Sopenharmony_ci "routerMap": [ 2609e41f4b71Sopenharmony_ci { 2610e41f4b71Sopenharmony_ci "name": "pageOne", 2611e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 2612e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 2613e41f4b71Sopenharmony_ci "data": { 2614e41f4b71Sopenharmony_ci "description": "this is pageOne" 2615e41f4b71Sopenharmony_ci } 2616e41f4b71Sopenharmony_ci }, 2617e41f4b71Sopenharmony_ci { 2618e41f4b71Sopenharmony_ci "name": "pageTwo", 2619e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageTwo.ets", 2620e41f4b71Sopenharmony_ci "buildFunction": "PageTwoBuilder" 2621e41f4b71Sopenharmony_ci } 2622e41f4b71Sopenharmony_ci ] 2623e41f4b71Sopenharmony_ci} 2624e41f4b71Sopenharmony_ci``` 2625e41f4b71Sopenharmony_ci 2626e41f4b71Sopenharmony_ci 2627e41f4b71Sopenharmony_ci### Example 5 2628e41f4b71Sopenharmony_ci 2629e41f4b71Sopenharmony_ciThis example demonstrates how to set the background color and background blur effect for the title bar of the home page in **Navigation**, as well as for the toolbar and the title bars on the **NavDestination** pages. 2630e41f4b71Sopenharmony_ci 2631e41f4b71Sopenharmony_ci```ts 2632e41f4b71Sopenharmony_cilet COLOR1: string = "#80004AAF"; 2633e41f4b71Sopenharmony_cilet COLOR2: string = "#802787D9"; 2634e41f4b71Sopenharmony_cilet BLUR_STYLE_1: BlurStyle = BlurStyle.BACKGROUND_THIN; 2635e41f4b71Sopenharmony_cilet BLUR_STYLE_2: BlurStyle = BlurStyle.BACKGROUND_THICK; 2636e41f4b71Sopenharmony_ci 2637e41f4b71Sopenharmony_ci@Component 2638e41f4b71Sopenharmony_cistruct BackComponent { 2639e41f4b71Sopenharmony_ci build() { 2640e41f4b71Sopenharmony_ci Row() { 2641e41f4b71Sopenharmony_ci Column() {} 2642e41f4b71Sopenharmony_ci .height('100%') 2643e41f4b71Sopenharmony_ci .backgroundColor("#3D9DB4") 2644e41f4b71Sopenharmony_ci .layoutWeight(9) 2645e41f4b71Sopenharmony_ci Column() {} 2646e41f4b71Sopenharmony_ci .height('100%') 2647e41f4b71Sopenharmony_ci .backgroundColor("17A98D") 2648e41f4b71Sopenharmony_ci .layoutWeight(9) 2649e41f4b71Sopenharmony_ci Column() {} 2650e41f4b71Sopenharmony_ci .height('100%') 2651e41f4b71Sopenharmony_ci .backgroundColor("FFC000") 2652e41f4b71Sopenharmony_ci .layoutWeight(9) 2653e41f4b71Sopenharmony_ci } 2654e41f4b71Sopenharmony_ci .height('100%') 2655e41f4b71Sopenharmony_ci .width('100%') 2656e41f4b71Sopenharmony_ci } 2657e41f4b71Sopenharmony_ci} 2658e41f4b71Sopenharmony_ci 2659e41f4b71Sopenharmony_ci@Component 2660e41f4b71Sopenharmony_cistruct ColorAndBlur { 2661e41f4b71Sopenharmony_ci @State useColor1: boolean = true; 2662e41f4b71Sopenharmony_ci @State useBlur1: boolean = true; 2663e41f4b71Sopenharmony_ci 2664e41f4b71Sopenharmony_ci build() { 2665e41f4b71Sopenharmony_ci NavDestination() { 2666e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2667e41f4b71Sopenharmony_ci BackComponent() 2668e41f4b71Sopenharmony_ci .width('100%') 2669e41f4b71Sopenharmony_ci .height('100%') 2670e41f4b71Sopenharmony_ci Column() { 2671e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2672e41f4b71Sopenharmony_ci Button("switch color") 2673e41f4b71Sopenharmony_ci .onClick(() => { 2674e41f4b71Sopenharmony_ci this.useColor1 = !this.useColor1; 2675e41f4b71Sopenharmony_ci }) 2676e41f4b71Sopenharmony_ci } 2677e41f4b71Sopenharmony_ci .width('100%') 2678e41f4b71Sopenharmony_ci .layoutWeight(1) 2679e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2680e41f4b71Sopenharmony_ci Button("switch blur") 2681e41f4b71Sopenharmony_ci .onClick(() => { 2682e41f4b71Sopenharmony_ci this.useBlur1 = !this.useBlur1; 2683e41f4b71Sopenharmony_ci }) 2684e41f4b71Sopenharmony_ci } 2685e41f4b71Sopenharmony_ci .width('100%') 2686e41f4b71Sopenharmony_ci .layoutWeight(1) 2687e41f4b71Sopenharmony_ci } 2688e41f4b71Sopenharmony_ci .width('100%') 2689e41f4b71Sopenharmony_ci .height('100%') 2690e41f4b71Sopenharmony_ci }.width('100%') 2691e41f4b71Sopenharmony_ci .height('100%') 2692e41f4b71Sopenharmony_ci } 2693e41f4b71Sopenharmony_ci .width('100%') 2694e41f4b71Sopenharmony_ci .height('100%') 2695e41f4b71Sopenharmony_ci // You can set the background color and background blur style of the title bar. 2696e41f4b71Sopenharmony_ci .title("switch titlebar color and blur", { 2697e41f4b71Sopenharmony_ci backgroundColor: this.useColor1 ? COLOR1 : COLOR2, 2698e41f4b71Sopenharmony_ci backgroundBlurStyle: this.useBlur1 ? BLUR_STYLE_1 : BLUR_STYLE_2, 2699e41f4b71Sopenharmony_ci barStyle: BarStyle.STACK 2700e41f4b71Sopenharmony_ci }) 2701e41f4b71Sopenharmony_ci } 2702e41f4b71Sopenharmony_ci} 2703e41f4b71Sopenharmony_ci 2704e41f4b71Sopenharmony_ci@Entry 2705e41f4b71Sopenharmony_ci@Component 2706e41f4b71Sopenharmony_cistruct Index { 2707e41f4b71Sopenharmony_ci private stack: NavPathStack = new NavPathStack(); 2708e41f4b71Sopenharmony_ci @State useColor1: boolean = true; 2709e41f4b71Sopenharmony_ci @State useBlur1: boolean = true; 2710e41f4b71Sopenharmony_ci 2711e41f4b71Sopenharmony_ci @Builder 2712e41f4b71Sopenharmony_ci PageBuilder(name: string) { 2713e41f4b71Sopenharmony_ci ColorAndBlur() 2714e41f4b71Sopenharmony_ci } 2715e41f4b71Sopenharmony_ci 2716e41f4b71Sopenharmony_ci build() { 2717e41f4b71Sopenharmony_ci Navigation(this.stack) { 2718e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2719e41f4b71Sopenharmony_ci BackComponent() 2720e41f4b71Sopenharmony_ci .width('100%') 2721e41f4b71Sopenharmony_ci .height('100%') 2722e41f4b71Sopenharmony_ci Column() { 2723e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2724e41f4b71Sopenharmony_ci Button("switch color") 2725e41f4b71Sopenharmony_ci .onClick(() => { 2726e41f4b71Sopenharmony_ci this.useColor1 = !this.useColor1; 2727e41f4b71Sopenharmony_ci }) 2728e41f4b71Sopenharmony_ci } 2729e41f4b71Sopenharmony_ci .width('100%') 2730e41f4b71Sopenharmony_ci .layoutWeight(1) 2731e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2732e41f4b71Sopenharmony_ci Button("switch blur") 2733e41f4b71Sopenharmony_ci .onClick(() => { 2734e41f4b71Sopenharmony_ci this.useBlur1 = !this.useBlur1; 2735e41f4b71Sopenharmony_ci }) 2736e41f4b71Sopenharmony_ci } 2737e41f4b71Sopenharmony_ci .width('100%') 2738e41f4b71Sopenharmony_ci .layoutWeight(1) 2739e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2740e41f4b71Sopenharmony_ci Button("push page") 2741e41f4b71Sopenharmony_ci .onClick(() => { 2742e41f4b71Sopenharmony_ci this.stack.pushPath({name: "page"}) 2743e41f4b71Sopenharmony_ci }) 2744e41f4b71Sopenharmony_ci } 2745e41f4b71Sopenharmony_ci .width('100%') 2746e41f4b71Sopenharmony_ci .layoutWeight(1) 2747e41f4b71Sopenharmony_ci } 2748e41f4b71Sopenharmony_ci .width('100%') 2749e41f4b71Sopenharmony_ci .height('80%') 2750e41f4b71Sopenharmony_ci }.width('100%') 2751e41f4b71Sopenharmony_ci .height('100%') 2752e41f4b71Sopenharmony_ci } 2753e41f4b71Sopenharmony_ci .width('100%') 2754e41f4b71Sopenharmony_ci .height('100%') 2755e41f4b71Sopenharmony_ci .navDestination(this.PageBuilder) 2756e41f4b71Sopenharmony_ci // You can set the background color and background blur style of the title bar. 2757e41f4b71Sopenharmony_ci .title("NavTitle", { 2758e41f4b71Sopenharmony_ci backgroundColor: this.useColor1 ? COLOR1 : COLOR2, 2759e41f4b71Sopenharmony_ci backgroundBlurStyle: this.useBlur1 ? BLUR_STYLE_1 : BLUR_STYLE_2, 2760e41f4b71Sopenharmony_ci barStyle: BarStyle.STACK 2761e41f4b71Sopenharmony_ci }) 2762e41f4b71Sopenharmony_ci // You can set the background color and background blur style of the toolbar. 2763e41f4b71Sopenharmony_ci .toolbarConfiguration([ 2764e41f4b71Sopenharmony_ci {value: "a"}, 2765e41f4b71Sopenharmony_ci {value: "b"}, 2766e41f4b71Sopenharmony_ci {value: "c"} 2767e41f4b71Sopenharmony_ci ], { 2768e41f4b71Sopenharmony_ci backgroundColor: this.useColor1 ? COLOR1 : COLOR2, 2769e41f4b71Sopenharmony_ci backgroundBlurStyle: this.useBlur1 ? BLUR_STYLE_1 : BLUR_STYLE_2 2770e41f4b71Sopenharmony_ci }) 2771e41f4b71Sopenharmony_ci } 2772e41f4b71Sopenharmony_ci} 2773e41f4b71Sopenharmony_ci``` 2774e41f4b71Sopenharmony_ci 2775e41f4b71Sopenharmony_ci 2776e41f4b71Sopenharmony_ci### Example 6 2777e41f4b71Sopenharmony_ci 2778e41f4b71Sopenharmony_ciThis example shows how to obtain the parent navigation path stack for a nested **Navigation** component. 2779e41f4b71Sopenharmony_ci 2780e41f4b71Sopenharmony_ci```ts 2781e41f4b71Sopenharmony_ci@Entry 2782e41f4b71Sopenharmony_ci@Component 2783e41f4b71Sopenharmony_cistruct NavigationExample1 { 2784e41f4b71Sopenharmony_ci @State childNavStack: NavPathStack = new NavPathStack(); 2785e41f4b71Sopenharmony_ci 2786e41f4b71Sopenharmony_ci build() { 2787e41f4b71Sopenharmony_ci Navigation() { 2788e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2789e41f4b71Sopenharmony_ci Navigation(this.childNavStack) { 2790e41f4b71Sopenharmony_ci Button('push Path to parent Navigation', { stateEffect: true, type: ButtonType.Capsule }) 2791e41f4b71Sopenharmony_ci .width('80%') 2792e41f4b71Sopenharmony_ci .height(40) 2793e41f4b71Sopenharmony_ci .margin(20) 2794e41f4b71Sopenharmony_ci .onClick(() => { 2795e41f4b71Sopenharmony_ci // The parent the parent navigation path stack can be obtained. 2796e41f4b71Sopenharmony_ci let parentStack = this.childNavStack.getParent(); 2797e41f4b71Sopenharmony_ci parentStack?.pushPath({ name: "pageOne"}) 2798e41f4b71Sopenharmony_ci }) 2799e41f4b71Sopenharmony_ci } 2800e41f4b71Sopenharmony_ci .clip(true) 2801e41f4b71Sopenharmony_ci .backgroundColor(Color.Orange) 2802e41f4b71Sopenharmony_ci .width('80%') 2803e41f4b71Sopenharmony_ci .height('80%') 2804e41f4b71Sopenharmony_ci .title('ChildNavigation') 2805e41f4b71Sopenharmony_ci } 2806e41f4b71Sopenharmony_ci .width('100%') 2807e41f4b71Sopenharmony_ci .height('100%') 2808e41f4b71Sopenharmony_ci } 2809e41f4b71Sopenharmony_ci .backgroundColor(Color.Green) 2810e41f4b71Sopenharmony_ci .width('100%') 2811e41f4b71Sopenharmony_ci .height('100%') 2812e41f4b71Sopenharmony_ci .title('ParentNavigation') 2813e41f4b71Sopenharmony_ci } 2814e41f4b71Sopenharmony_ci} 2815e41f4b71Sopenharmony_ci``` 2816e41f4b71Sopenharmony_ci```ts 2817e41f4b71Sopenharmony_ci// PageOne.ets 2818e41f4b71Sopenharmony_ci @Builder 2819e41f4b71Sopenharmony_ci export function PageOneBuilder(name: string) { 2820e41f4b71Sopenharmony_ci NavDestination() { 2821e41f4b71Sopenharmony_ci Text("this is " + name) 2822e41f4b71Sopenharmony_ci } 2823e41f4b71Sopenharmony_ci .title(name) 2824e41f4b71Sopenharmony_ci } 2825e41f4b71Sopenharmony_ci``` 2826e41f4b71Sopenharmony_ci```json 2827e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 2828e41f4b71Sopenharmony_ci// route_map.json 2829e41f4b71Sopenharmony_ci{ 2830e41f4b71Sopenharmony_ci "routerMap": [ 2831e41f4b71Sopenharmony_ci { 2832e41f4b71Sopenharmony_ci "name": "pageOne", 2833e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 2834e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 2835e41f4b71Sopenharmony_ci "data": { 2836e41f4b71Sopenharmony_ci "description": "this is pageOne" 2837e41f4b71Sopenharmony_ci } 2838e41f4b71Sopenharmony_ci } 2839e41f4b71Sopenharmony_ci ] 2840e41f4b71Sopenharmony_ci} 2841e41f4b71Sopenharmony_ci``` 2842e41f4b71Sopenharmony_ci 2843e41f4b71Sopenharmony_ci 2844e41f4b71Sopenharmony_ci### Example 7 2845e41f4b71Sopenharmony_ci 2846e41f4b71Sopenharmony_ciThis example demonstrates the following: 2847e41f4b71Sopenharmony_ci 2848e41f4b71Sopenharmony_ci1. The navigation stack operation can be conducted even when **NavPathStack** is not declared as a state variable. 2849e41f4b71Sopenharmony_ci 2850e41f4b71Sopenharmony_ci2. The **NavDestination** can obtain the corresponding **NavPathInfo** and **NavPathStack** through the **onReady** event. 2851e41f4b71Sopenharmony_ci 2852e41f4b71Sopenharmony_ci```ts 2853e41f4b71Sopenharmony_ciclass PageParam { 2854e41f4b71Sopenharmony_ci constructor(num_: number) { 2855e41f4b71Sopenharmony_ci this.num = num_; 2856e41f4b71Sopenharmony_ci } 2857e41f4b71Sopenharmony_ci num: number = 0; 2858e41f4b71Sopenharmony_ci} 2859e41f4b71Sopenharmony_ci 2860e41f4b71Sopenharmony_ci@Builder 2861e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 2862e41f4b71Sopenharmony_ci PageOne() 2863e41f4b71Sopenharmony_ci} 2864e41f4b71Sopenharmony_ci 2865e41f4b71Sopenharmony_ci@Component 2866e41f4b71Sopenharmony_cistruct PageOne { 2867e41f4b71Sopenharmony_ci private stack: NavPathStack | null = null; 2868e41f4b71Sopenharmony_ci private name: string = ""; 2869e41f4b71Sopenharmony_ci private paramNum: number = 0; 2870e41f4b71Sopenharmony_ci 2871e41f4b71Sopenharmony_ci build() { 2872e41f4b71Sopenharmony_ci NavDestination() { 2873e41f4b71Sopenharmony_ci Column() { 2874e41f4b71Sopenharmony_ci Text("NavPathInfo: name: " + this.name + ", paramNum: " + this.paramNum) 2875e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 2876e41f4b71Sopenharmony_ci .width('80%') 2877e41f4b71Sopenharmony_ci .height(40) 2878e41f4b71Sopenharmony_ci .margin(20) 2879e41f4b71Sopenharmony_ci .onClick(() => { 2880e41f4b71Sopenharmony_ci if (this.stack) { 2881e41f4b71Sopenharmony_ci let p = new PageParam(this.paramNum + 1); 2882e41f4b71Sopenharmony_ci this.stack.pushPath({name: "pageOne", param: p}); 2883e41f4b71Sopenharmony_ci } 2884e41f4b71Sopenharmony_ci }) 2885e41f4b71Sopenharmony_ci Button('pop', { stateEffect: true, type: ButtonType.Capsule }) 2886e41f4b71Sopenharmony_ci .width('80%') 2887e41f4b71Sopenharmony_ci .height(40) 2888e41f4b71Sopenharmony_ci .margin(20) 2889e41f4b71Sopenharmony_ci .onClick(() => { 2890e41f4b71Sopenharmony_ci this.stack?.pop() 2891e41f4b71Sopenharmony_ci }) 2892e41f4b71Sopenharmony_ci } 2893e41f4b71Sopenharmony_ci .width('100%') 2894e41f4b71Sopenharmony_ci .height('100%') 2895e41f4b71Sopenharmony_ci } 2896e41f4b71Sopenharmony_ci .title('pageOne') 2897e41f4b71Sopenharmony_ci .onReady((ctx: NavDestinationContext) => { 2898e41f4b71Sopenharmony_ci // The passed NavPathInfo and the owning NavPathStack objects can be obtained for <NavDestination>. 2899e41f4b71Sopenharmony_ci try { 2900e41f4b71Sopenharmony_ci this.name = ctx?.pathInfo?.name; 2901e41f4b71Sopenharmony_ci this.paramNum = (ctx?.pathInfo?.param as PageParam)?.num; 2902e41f4b71Sopenharmony_ci this.stack = ctx.pathStack; 2903e41f4b71Sopenharmony_ci } catch (e) { 2904e41f4b71Sopenharmony_ci console.log(`testTag onReady catch exception: ${JSON.stringify(e)}`) 2905e41f4b71Sopenharmony_ci } 2906e41f4b71Sopenharmony_ci }) 2907e41f4b71Sopenharmony_ci } 2908e41f4b71Sopenharmony_ci} 2909e41f4b71Sopenharmony_ci 2910e41f4b71Sopenharmony_ci@Entry 2911e41f4b71Sopenharmony_ci@Component 2912e41f4b71Sopenharmony_cistruct NavigationExample2 { 2913e41f4b71Sopenharmony_ci private stack : NavPathStack = new NavPathStack(); 2914e41f4b71Sopenharmony_ci 2915e41f4b71Sopenharmony_ci build() { 2916e41f4b71Sopenharmony_ci Navigation(this.stack) { 2917e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 2918e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 2919e41f4b71Sopenharmony_ci .width('80%') 2920e41f4b71Sopenharmony_ci .height(40) 2921e41f4b71Sopenharmony_ci .margin(20) 2922e41f4b71Sopenharmony_ci .onClick(() => { 2923e41f4b71Sopenharmony_ci let p = new PageParam(1); 2924e41f4b71Sopenharmony_ci this.stack.pushPath({ name: "pageOne", param: p }) 2925e41f4b71Sopenharmony_ci }) 2926e41f4b71Sopenharmony_ci } 2927e41f4b71Sopenharmony_ci .width('100%') 2928e41f4b71Sopenharmony_ci .height('100%') 2929e41f4b71Sopenharmony_ci } 2930e41f4b71Sopenharmony_ci .width('100%') 2931e41f4b71Sopenharmony_ci .height('100%') 2932e41f4b71Sopenharmony_ci .title('Navigation') 2933e41f4b71Sopenharmony_ci } 2934e41f4b71Sopenharmony_ci} 2935e41f4b71Sopenharmony_ci``` 2936e41f4b71Sopenharmony_ci```json 2937e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 2938e41f4b71Sopenharmony_ci// route_map.json 2939e41f4b71Sopenharmony_ci{ 2940e41f4b71Sopenharmony_ci "routerMap": [ 2941e41f4b71Sopenharmony_ci { 2942e41f4b71Sopenharmony_ci "name": "pageOne", 2943e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/Index.ets", 2944e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 2945e41f4b71Sopenharmony_ci "data": { 2946e41f4b71Sopenharmony_ci "description": "this is pageOne" 2947e41f4b71Sopenharmony_ci } 2948e41f4b71Sopenharmony_ci } 2949e41f4b71Sopenharmony_ci ] 2950e41f4b71Sopenharmony_ci} 2951e41f4b71Sopenharmony_ci``` 2952e41f4b71Sopenharmony_ci 2953e41f4b71Sopenharmony_ci 2954e41f4b71Sopenharmony_ci### Example 8 2955e41f4b71Sopenharmony_ci 2956e41f4b71Sopenharmony_ciThis example demonstrates the lifecycle timing of **NavDestination**. 2957e41f4b71Sopenharmony_ci 2958e41f4b71Sopenharmony_ci```ts 2959e41f4b71Sopenharmony_ci@Builder 2960e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 2961e41f4b71Sopenharmony_ci PageOneComponent() 2962e41f4b71Sopenharmony_ci} 2963e41f4b71Sopenharmony_ci 2964e41f4b71Sopenharmony_ci@Component 2965e41f4b71Sopenharmony_cistruct PageOneComponent { 2966e41f4b71Sopenharmony_ci private stack: NavPathStack | null = null; 2967e41f4b71Sopenharmony_ci @State eventStr: string = ""; 2968e41f4b71Sopenharmony_ci 2969e41f4b71Sopenharmony_ci build() { 2970e41f4b71Sopenharmony_ci NavDestination() { 2971e41f4b71Sopenharmony_ci Column() { 2972e41f4b71Sopenharmony_ci Text("event: " + this.eventStr) 2973e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 2974e41f4b71Sopenharmony_ci .width('80%') 2975e41f4b71Sopenharmony_ci .height(40) 2976e41f4b71Sopenharmony_ci .margin(20) 2977e41f4b71Sopenharmony_ci .onClick(() => { 2978e41f4b71Sopenharmony_ci if (this.stack) { 2979e41f4b71Sopenharmony_ci this.stack.pushPath({name: "pageOne"}); 2980e41f4b71Sopenharmony_ci } 2981e41f4b71Sopenharmony_ci }) 2982e41f4b71Sopenharmony_ci Button('pop', { stateEffect: true, type: ButtonType.Capsule }) 2983e41f4b71Sopenharmony_ci .width('80%') 2984e41f4b71Sopenharmony_ci .height(40) 2985e41f4b71Sopenharmony_ci .margin(20) 2986e41f4b71Sopenharmony_ci .onClick(() => { 2987e41f4b71Sopenharmony_ci this.stack?.pop() 2988e41f4b71Sopenharmony_ci }) 2989e41f4b71Sopenharmony_ci } 2990e41f4b71Sopenharmony_ci .width('100%') 2991e41f4b71Sopenharmony_ci .height('100%') 2992e41f4b71Sopenharmony_ci } 2993e41f4b71Sopenharmony_ci .title('pageOne') 2994e41f4b71Sopenharmony_ci .onAppear(() => { this.eventStr += "<onAppear>"; }) 2995e41f4b71Sopenharmony_ci .onDisAppear(() => { this.eventStr += "<onDisAppear>"; }) 2996e41f4b71Sopenharmony_ci .onShown(() => { this.eventStr += "<onShown>"; }) 2997e41f4b71Sopenharmony_ci .onHidden(() => { this.eventStr += "<onHidden>"; }) 2998e41f4b71Sopenharmony_ci .onWillAppear(() => { this.eventStr += "<onWillAppear>"; }) 2999e41f4b71Sopenharmony_ci .onWillDisappear(() => { this.eventStr += "<onWillDisappear>"; }) 3000e41f4b71Sopenharmony_ci .onWillShow(() => { this.eventStr += "<onWillShow>"; }) 3001e41f4b71Sopenharmony_ci .onWillHide(() => { this.eventStr += "<onWillHide>"; }) 3002e41f4b71Sopenharmony_ci // onReady is called before onAppear. 3003e41f4b71Sopenharmony_ci .onReady((ctx: NavDestinationContext) => { 3004e41f4b71Sopenharmony_ci try { 3005e41f4b71Sopenharmony_ci this.eventStr += "<onReady>"; 3006e41f4b71Sopenharmony_ci this.stack = ctx.pathStack; 3007e41f4b71Sopenharmony_ci } catch (e) { 3008e41f4b71Sopenharmony_ci console.log(`testTag onReady catch exception: ${JSON.stringify(e)}`) 3009e41f4b71Sopenharmony_ci } 3010e41f4b71Sopenharmony_ci }) 3011e41f4b71Sopenharmony_ci } 3012e41f4b71Sopenharmony_ci} 3013e41f4b71Sopenharmony_ci 3014e41f4b71Sopenharmony_ci@Entry 3015e41f4b71Sopenharmony_ci@Component 3016e41f4b71Sopenharmony_cistruct NavigationExample3 { 3017e41f4b71Sopenharmony_ci private stack : NavPathStack = new NavPathStack(); 3018e41f4b71Sopenharmony_ci 3019e41f4b71Sopenharmony_ci build() { 3020e41f4b71Sopenharmony_ci Navigation(this.stack) { 3021e41f4b71Sopenharmony_ci Stack({alignContent: Alignment.Center}) { 3022e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 3023e41f4b71Sopenharmony_ci .width('80%') 3024e41f4b71Sopenharmony_ci .height(40) 3025e41f4b71Sopenharmony_ci .margin(20) 3026e41f4b71Sopenharmony_ci .onClick(() => { 3027e41f4b71Sopenharmony_ci this.stack.pushPath({ name: "pageOne" }) 3028e41f4b71Sopenharmony_ci }) 3029e41f4b71Sopenharmony_ci } 3030e41f4b71Sopenharmony_ci .width('100%') 3031e41f4b71Sopenharmony_ci .height('100%') 3032e41f4b71Sopenharmony_ci } 3033e41f4b71Sopenharmony_ci .width('100%') 3034e41f4b71Sopenharmony_ci .height('100%') 3035e41f4b71Sopenharmony_ci .title('Navigation') 3036e41f4b71Sopenharmony_ci } 3037e41f4b71Sopenharmony_ci} 3038e41f4b71Sopenharmony_ci``` 3039e41f4b71Sopenharmony_ci```json 3040e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 3041e41f4b71Sopenharmony_ci// route_map.json 3042e41f4b71Sopenharmony_ci{ 3043e41f4b71Sopenharmony_ci "routerMap": [ 3044e41f4b71Sopenharmony_ci { 3045e41f4b71Sopenharmony_ci "name": "pageOne", 3046e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/Index.ets", 3047e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 3048e41f4b71Sopenharmony_ci "data": { 3049e41f4b71Sopenharmony_ci "description": "this is pageOne" 3050e41f4b71Sopenharmony_ci } 3051e41f4b71Sopenharmony_ci } 3052e41f4b71Sopenharmony_ci ] 3053e41f4b71Sopenharmony_ci} 3054e41f4b71Sopenharmony_ci``` 3055e41f4b71Sopenharmony_ci 3056e41f4b71Sopenharmony_ci 3057e41f4b71Sopenharmony_ci 3058e41f4b71Sopenharmony_ci### Example 9 3059e41f4b71Sopenharmony_ci 3060e41f4b71Sopenharmony_ciThis example demonstrates the stack layout of the title bar in the **Navigation** component. 3061e41f4b71Sopenharmony_ci 3062e41f4b71Sopenharmony_ci```ts 3063e41f4b71Sopenharmony_ci@Entry 3064e41f4b71Sopenharmony_ci@Component 3065e41f4b71Sopenharmony_cistruct NavigationExample { 3066e41f4b71Sopenharmony_ci private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; 3067e41f4b71Sopenharmony_ci private scrollerForScroll: Scroller = new Scroller(); 3068e41f4b71Sopenharmony_ci @State barStyle: BarStyle = BarStyle.STANDARD; 3069e41f4b71Sopenharmony_ci 3070e41f4b71Sopenharmony_ci build() { 3071e41f4b71Sopenharmony_ci Column() { 3072e41f4b71Sopenharmony_ci Navigation() { 3073e41f4b71Sopenharmony_ci Column() { 3074e41f4b71Sopenharmony_ci Scroll(this.scrollerForScroll) { 3075e41f4b71Sopenharmony_ci Column() { 3076e41f4b71Sopenharmony_ci Image($r('app.media.image_1')) 3077e41f4b71Sopenharmony_ci // Set the height to be the same as that of the title bar to better observe the stack effect. 3078e41f4b71Sopenharmony_ci .height(138) 3079e41f4b71Sopenharmony_ci .width('100%') 3080e41f4b71Sopenharmony_ci Button('BarStyle.STANDARD') 3081e41f4b71Sopenharmony_ci .height('50vp') 3082e41f4b71Sopenharmony_ci .onClick(() => { 3083e41f4b71Sopenharmony_ci this.barStyle = BarStyle.STANDARD; 3084e41f4b71Sopenharmony_ci }) 3085e41f4b71Sopenharmony_ci Button('BarStyle.STACK') 3086e41f4b71Sopenharmony_ci .height('50vp') 3087e41f4b71Sopenharmony_ci .margin({ top: 12 }) 3088e41f4b71Sopenharmony_ci .onClick(() => { 3089e41f4b71Sopenharmony_ci this.barStyle = BarStyle.STACK; 3090e41f4b71Sopenharmony_ci }) 3091e41f4b71Sopenharmony_ci 3092e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 3093e41f4b71Sopenharmony_ci ListItem() { 3094e41f4b71Sopenharmony_ci Text('' + item) 3095e41f4b71Sopenharmony_ci .width('100%') 3096e41f4b71Sopenharmony_ci .height(100) 3097e41f4b71Sopenharmony_ci .fontSize(16) 3098e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 3099e41f4b71Sopenharmony_ci .borderRadius(10) 3100e41f4b71Sopenharmony_ci .backgroundColor(Color.Orange) 3101e41f4b71Sopenharmony_ci .margin({ top: 12 }) 3102e41f4b71Sopenharmony_ci } 3103e41f4b71Sopenharmony_ci }, (item: string) => item) 3104e41f4b71Sopenharmony_ci } 3105e41f4b71Sopenharmony_ci } 3106e41f4b71Sopenharmony_ci } 3107e41f4b71Sopenharmony_ci .width('100%') 3108e41f4b71Sopenharmony_ci .height('100%') 3109e41f4b71Sopenharmony_ci .backgroundColor(0xDCDCDC) 3110e41f4b71Sopenharmony_ci } 3111e41f4b71Sopenharmony_ci .title( 3112e41f4b71Sopenharmony_ci { 3113e41f4b71Sopenharmony_ci main: 'NavTitle', 3114e41f4b71Sopenharmony_ci sub: 'subtitle' 3115e41f4b71Sopenharmony_ci }, 3116e41f4b71Sopenharmony_ci { 3117e41f4b71Sopenharmony_ci backgroundBlurStyle: BlurStyle.COMPONENT_THICK, 3118e41f4b71Sopenharmony_ci barStyle: this.barStyle, 3119e41f4b71Sopenharmony_ci } 3120e41f4b71Sopenharmony_ci ) 3121e41f4b71Sopenharmony_ci .titleMode(NavigationTitleMode.Free) 3122e41f4b71Sopenharmony_ci .hideTitleBar(false) 3123e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor('#F1F3F5') 3124e41f4b71Sopenharmony_ci } 3125e41f4b71Sopenharmony_ci} 3126e41f4b71Sopenharmony_ci``` 3127e41f4b71Sopenharmony_ci 3128e41f4b71Sopenharmony_ci 3129e41f4b71Sopenharmony_ci 3130e41f4b71Sopenharmony_ci### Example 10 3131e41f4b71Sopenharmony_ci 3132e41f4b71Sopenharmony_ciThis example demonstrates how to define a derived class of **NavPathStack** and the basic usage of the derived class in **Navigation**. 3133e41f4b71Sopenharmony_ci 3134e41f4b71Sopenharmony_ci```ts 3135e41f4b71Sopenharmony_ciclass DerivedNavPathStack extends NavPathStack { 3136e41f4b71Sopenharmony_ci // usr defined property 'id' 3137e41f4b71Sopenharmony_ci id: string = "__default__" 3138e41f4b71Sopenharmony_ci 3139e41f4b71Sopenharmony_ci // new function in derived class 3140e41f4b71Sopenharmony_ci setId(id: string) { 3141e41f4b71Sopenharmony_ci this.id = id; 3142e41f4b71Sopenharmony_ci } 3143e41f4b71Sopenharmony_ci 3144e41f4b71Sopenharmony_ci // new function in derived class 3145e41f4b71Sopenharmony_ci getInfo(): string { 3146e41f4b71Sopenharmony_ci return "this page used Derived NavPathStack, id: " + this.id 3147e41f4b71Sopenharmony_ci } 3148e41f4b71Sopenharmony_ci 3149e41f4b71Sopenharmony_ci // overwrite function of NavPathStack 3150e41f4b71Sopenharmony_ci pushPath(info: NavPathInfo, animated?: boolean): void 3151e41f4b71Sopenharmony_ci pushPath(info: NavPathInfo, options?: NavigationOptions): void 3152e41f4b71Sopenharmony_ci pushPath(info: NavPathInfo, secArg?: boolean | NavigationOptions): void { 3153e41f4b71Sopenharmony_ci console.log('[derive-test] reached DerivedNavPathStack\'s pushPath'); 3154e41f4b71Sopenharmony_ci if (typeof secArg === 'boolean') { 3155e41f4b71Sopenharmony_ci super.pushPath(info, secArg); 3156e41f4b71Sopenharmony_ci } else { 3157e41f4b71Sopenharmony_ci super.pushPath(info, secArg); 3158e41f4b71Sopenharmony_ci } 3159e41f4b71Sopenharmony_ci } 3160e41f4b71Sopenharmony_ci 3161e41f4b71Sopenharmony_ci // overwrite and overload function of NavPathStack 3162e41f4b71Sopenharmony_ci pop(animated?: boolean | undefined): NavPathInfo | undefined 3163e41f4b71Sopenharmony_ci pop(result: Object, animated?: boolean | undefined): NavPathInfo | undefined 3164e41f4b71Sopenharmony_ci pop(result?: Object, animated?: boolean | undefined): NavPathInfo | undefined { 3165e41f4b71Sopenharmony_ci console.log('[derive-test] reached DerivedNavPathStack\'s pop'); 3166e41f4b71Sopenharmony_ci return super.pop(result, animated); 3167e41f4b71Sopenharmony_ci } 3168e41f4b71Sopenharmony_ci 3169e41f4b71Sopenharmony_ci // other function of base class... 3170e41f4b71Sopenharmony_ci} 3171e41f4b71Sopenharmony_ci 3172e41f4b71Sopenharmony_ciclass param { 3173e41f4b71Sopenharmony_ci info: string = "__default_param__"; 3174e41f4b71Sopenharmony_ci constructor(info: string) { this.info = info } 3175e41f4b71Sopenharmony_ci} 3176e41f4b71Sopenharmony_ci 3177e41f4b71Sopenharmony_ci@Entry 3178e41f4b71Sopenharmony_ci@Component 3179e41f4b71Sopenharmony_cistruct Index { 3180e41f4b71Sopenharmony_ci derivedStack: DerivedNavPathStack = new DerivedNavPathStack(); 3181e41f4b71Sopenharmony_ci 3182e41f4b71Sopenharmony_ci aboutToAppear(): void { 3183e41f4b71Sopenharmony_ci this.derivedStack.setId('origin stack'); 3184e41f4b71Sopenharmony_ci } 3185e41f4b71Sopenharmony_ci 3186e41f4b71Sopenharmony_ci @Builder 3187e41f4b71Sopenharmony_ci pageMap(name: string) { 3188e41f4b71Sopenharmony_ci PageOne() 3189e41f4b71Sopenharmony_ci } 3190e41f4b71Sopenharmony_ci 3191e41f4b71Sopenharmony_ci build() { 3192e41f4b71Sopenharmony_ci Navigation(this.derivedStack) { 3193e41f4b71Sopenharmony_ci Button('to Page One').margin(20).onClick(() => { 3194e41f4b71Sopenharmony_ci this.derivedStack.pushPath({ 3195e41f4b71Sopenharmony_ci name: 'pageOne', 3196e41f4b71Sopenharmony_ci param: new param('push pageOne in homePage when stack size: ' + this.derivedStack.size()) 3197e41f4b71Sopenharmony_ci }); 3198e41f4b71Sopenharmony_ci }) 3199e41f4b71Sopenharmony_ci }.navDestination(this.pageMap) 3200e41f4b71Sopenharmony_ci .title('Home Page') 3201e41f4b71Sopenharmony_ci } 3202e41f4b71Sopenharmony_ci} 3203e41f4b71Sopenharmony_ci 3204e41f4b71Sopenharmony_ci@Component 3205e41f4b71Sopenharmony_cistruct PageOne { 3206e41f4b71Sopenharmony_ci derivedStack: DerivedNavPathStack = new DerivedNavPathStack(); 3207e41f4b71Sopenharmony_ci curStringifyParam: string = "NA"; 3208e41f4b71Sopenharmony_ci 3209e41f4b71Sopenharmony_ci build() { 3210e41f4b71Sopenharmony_ci NavDestination() { 3211e41f4b71Sopenharmony_ci Column() { 3212e41f4b71Sopenharmony_ci Text(this.derivedStack.getInfo()) 3213e41f4b71Sopenharmony_ci .margin(10) 3214e41f4b71Sopenharmony_ci .fontSize(25) 3215e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 3216e41f4b71Sopenharmony_ci .textAlign(TextAlign.Start) 3217e41f4b71Sopenharmony_ci Text('current page param info:') 3218e41f4b71Sopenharmony_ci .margin(10) 3219e41f4b71Sopenharmony_ci .fontSize(25) 3220e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 3221e41f4b71Sopenharmony_ci .textAlign(TextAlign.Start) 3222e41f4b71Sopenharmony_ci Text(this.curStringifyParam) 3223e41f4b71Sopenharmony_ci .margin(20) 3224e41f4b71Sopenharmony_ci .fontSize(20) 3225e41f4b71Sopenharmony_ci .textAlign(TextAlign.Start) 3226e41f4b71Sopenharmony_ci }.backgroundColor(Color.Pink) 3227e41f4b71Sopenharmony_ci Button('to Page One').margin(20).onClick(() => { 3228e41f4b71Sopenharmony_ci this.derivedStack.pushPath({ 3229e41f4b71Sopenharmony_ci name: 'pageOne', 3230e41f4b71Sopenharmony_ci param: new param('push pageOne in pageOne when stack size: ' + this.derivedStack.size()) 3231e41f4b71Sopenharmony_ci }); 3232e41f4b71Sopenharmony_ci }) 3233e41f4b71Sopenharmony_ci }.title('Page One') 3234e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 3235e41f4b71Sopenharmony_ci console.log('[derive-test] reached PageOne\'s onReady'); 3236e41f4b71Sopenharmony_ci // get derived stack from navdestinationContext 3237e41f4b71Sopenharmony_ci this.derivedStack = context.pathStack as DerivedNavPathStack; 3238e41f4b71Sopenharmony_ci console.log('[derive-test] -- got derivedStack: ' + this.derivedStack.id); 3239e41f4b71Sopenharmony_ci this.curStringifyParam = JSON.stringify(context.pathInfo.param); 3240e41f4b71Sopenharmony_ci console.log('[derive-test] -- got param: ' + this.curStringifyParam); 3241e41f4b71Sopenharmony_ci }) 3242e41f4b71Sopenharmony_ci } 3243e41f4b71Sopenharmony_ci} 3244e41f4b71Sopenharmony_ci``` 3245e41f4b71Sopenharmony_ci 3246e41f4b71Sopenharmony_ci 3247e41f4b71Sopenharmony_ci### Example 11 3248e41f4b71Sopenharmony_ci 3249e41f4b71Sopenharmony_ciThis example shows how to use symbol icons in **Navigation** and **NavDestination**. 3250e41f4b71Sopenharmony_ci 3251e41f4b71Sopenharmony_ci```ts 3252e41f4b71Sopenharmony_ciimport { SymbolGlyphModifier } from '@kit.ArkUI'; 3253e41f4b71Sopenharmony_ci 3254e41f4b71Sopenharmony_ci@Entry 3255e41f4b71Sopenharmony_ci@Component 3256e41f4b71Sopenharmony_cistruct NavigationExample { 3257e41f4b71Sopenharmony_ci @Provide('navPathStack') navPathStack:NavPathStack = new NavPathStack(); 3258e41f4b71Sopenharmony_ci @State menuItems:Array<NavigationMenuItem> = [ 3259e41f4b71Sopenharmony_ci { 3260e41f4b71Sopenharmony_ci value:'menuItem1', 3261e41f4b71Sopenharmony_ci icon:'resources/base/media/ic_public_ok.svg' // Icon resource path. 3262e41f4b71Sopenharmony_ci }, 3263e41f4b71Sopenharmony_ci { 3264e41f4b71Sopenharmony_ci value:'menuItem2', 3265e41f4b71Sopenharmony_ci icon:'resources/base/media/ic_public_ok.svg', // Icon resource path. 3266e41f4b71Sopenharmony_ci symbolIcon: new SymbolGlyphModifier($r('sys.symbol.ohos_folder_badge_plus')).fontColor([Color.Red,Color.Green]).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR), 3267e41f4b71Sopenharmony_ci }, 3268e41f4b71Sopenharmony_ci { 3269e41f4b71Sopenharmony_ci value:'menuItem3', 3270e41f4b71Sopenharmony_ci symbolIcon: new SymbolGlyphModifier($r('sys.symbol.ohos_lungs')), 3271e41f4b71Sopenharmony_ci }, 3272e41f4b71Sopenharmony_ci ] 3273e41f4b71Sopenharmony_ci 3274e41f4b71Sopenharmony_ci @State toolItems:Array<ToolbarItem>= [ 3275e41f4b71Sopenharmony_ci { 3276e41f4b71Sopenharmony_ci value:'toolItem1', 3277e41f4b71Sopenharmony_ci icon:'resources/base/media/ic_public_ok.svg', // Icon resource path. 3278e41f4b71Sopenharmony_ci symbolIcon:new SymbolGlyphModifier($r('sys.symbol.ohos_lungs')), 3279e41f4b71Sopenharmony_ci status:ToolbarItemStatus.ACTIVE, 3280e41f4b71Sopenharmony_ci activeSymbolIcon: new SymbolGlyphModifier($r('sys.symbol.ohos_folder_badge_plus')).fontColor([Color.Red,Color.Green]).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR), 3281e41f4b71Sopenharmony_ci action:()=>{} 3282e41f4b71Sopenharmony_ci }, 3283e41f4b71Sopenharmony_ci { 3284e41f4b71Sopenharmony_ci value:'toolItem2', 3285e41f4b71Sopenharmony_ci symbolIcon:new SymbolGlyphModifier($r('sys.symbol.ohos_star')), 3286e41f4b71Sopenharmony_ci status:ToolbarItemStatus.ACTIVE, 3287e41f4b71Sopenharmony_ci activeIcon: 'resources/base/media/ic_public_more.svg', // Icon resource path. 3288e41f4b71Sopenharmony_ci action:()=>{} 3289e41f4b71Sopenharmony_ci }, 3290e41f4b71Sopenharmony_ci { 3291e41f4b71Sopenharmony_ci value:'toolItem3', 3292e41f4b71Sopenharmony_ci symbolIcon:new SymbolGlyphModifier($r('sys.symbol.ohos_star')), 3293e41f4b71Sopenharmony_ci status:ToolbarItemStatus.ACTIVE, 3294e41f4b71Sopenharmony_ci activeSymbolIcon: new SymbolGlyphModifier($r('sys.symbol.ohos_lungs')), 3295e41f4b71Sopenharmony_ci action:()=>{} 3296e41f4b71Sopenharmony_ci } 3297e41f4b71Sopenharmony_ci ] 3298e41f4b71Sopenharmony_ci 3299e41f4b71Sopenharmony_ci @Builder 3300e41f4b71Sopenharmony_ci myRouter(name:string,param?:Object) { 3301e41f4b71Sopenharmony_ci if(name === 'NavigationMenu') { 3302e41f4b71Sopenharmony_ci NavigationMenu(); 3303e41f4b71Sopenharmony_ci } 3304e41f4b71Sopenharmony_ci } 3305e41f4b71Sopenharmony_ci 3306e41f4b71Sopenharmony_ci build() { 3307e41f4b71Sopenharmony_ci Navigation(this.navPathStack) { 3308e41f4b71Sopenharmony_ci Column() { 3309e41f4b71Sopenharmony_ci Button('Go').onClick(()=> { 3310e41f4b71Sopenharmony_ci this.navPathStack.pushPathByName('NavigationMenu', null); 3311e41f4b71Sopenharmony_ci }) 3312e41f4b71Sopenharmony_ci } 3313e41f4b71Sopenharmony_ci } 3314e41f4b71Sopenharmony_ci .backButtonIcon(new SymbolGlyphModifier($r('sys.symbol.ohos_wifi'))) 3315e41f4b71Sopenharmony_ci .titleMode(NavigationTitleMode.Mini) 3316e41f4b71Sopenharmony_ci .menus(this.menuItems) 3317e41f4b71Sopenharmony_ci .toolbarConfiguration(this.toolItems) 3318e41f4b71Sopenharmony_ci .title('Level-1 page') 3319e41f4b71Sopenharmony_ci .navDestination(this.myRouter) 3320e41f4b71Sopenharmony_ci } 3321e41f4b71Sopenharmony_ci} 3322e41f4b71Sopenharmony_ci 3323e41f4b71Sopenharmony_ci@Component 3324e41f4b71Sopenharmony_ciexport struct NavigationMenu{ 3325e41f4b71Sopenharmony_ci @Consume('navPathStack') navPathStack:NavPathStack; 3326e41f4b71Sopenharmony_ci @State menuItems:Array<NavigationMenuItem> = [ 3327e41f4b71Sopenharmony_ci { 3328e41f4b71Sopenharmony_ci value:'menuItem1', 3329e41f4b71Sopenharmony_ci icon:'resources/base/media/ic_public_ok.svg', // Icon resource path. 3330e41f4b71Sopenharmony_ci action:()=>{} 3331e41f4b71Sopenharmony_ci }, 3332e41f4b71Sopenharmony_ci { 3333e41f4b71Sopenharmony_ci value:'menuItem2', 3334e41f4b71Sopenharmony_ci symbolIcon: new SymbolGlyphModifier($r('sys.symbol.ohos_folder_badge_plus')).fontColor([Color.Red,Color.Green]).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR), 3335e41f4b71Sopenharmony_ci action:()=>{} 3336e41f4b71Sopenharmony_ci }, 3337e41f4b71Sopenharmony_ci { 3338e41f4b71Sopenharmony_ci value:'menuItem3', 3339e41f4b71Sopenharmony_ci symbolIcon: new SymbolGlyphModifier($r('sys.symbol.repeat_1')), 3340e41f4b71Sopenharmony_ci action:()=>{} 3341e41f4b71Sopenharmony_ci }, 3342e41f4b71Sopenharmony_ci ] 3343e41f4b71Sopenharmony_ci 3344e41f4b71Sopenharmony_ci build() { 3345e41f4b71Sopenharmony_ci NavDestination(){ 3346e41f4b71Sopenharmony_ci Row() { 3347e41f4b71Sopenharmony_ci Column(){ 3348e41f4b71Sopenharmony_ci } 3349e41f4b71Sopenharmony_ci .width('100%') 3350e41f4b71Sopenharmony_ci } 3351e41f4b71Sopenharmony_ci .height('100%') 3352e41f4b71Sopenharmony_ci } 3353e41f4b71Sopenharmony_ci .hideTitleBar(false) 3354e41f4b71Sopenharmony_ci .title('NavDestination title') 3355e41f4b71Sopenharmony_ci .backgroundColor($r('sys.color.ohos_id_color_titlebar_sub_bg')) 3356e41f4b71Sopenharmony_ci .backButtonIcon(new SymbolGlyphModifier($r('sys.symbol.ohos_star')).fontColor([Color.Blue])) 3357e41f4b71Sopenharmony_ci .menus(this.menuItems) 3358e41f4b71Sopenharmony_ci } 3359e41f4b71Sopenharmony_ci} 3360e41f4b71Sopenharmony_ci``` 3361e41f4b71Sopenharmony_ci 3362e41f4b71Sopenharmony_ci 3363e41f4b71Sopenharmony_ci### Example 12 3364e41f4b71Sopenharmony_ci 3365e41f4b71Sopenharmony_ciThis example demonstrates how to set custom title bar padding in **Navigation** and **NavDestination**, and how to modify the main title and subtitle text styles through **TextModifier**. 3366e41f4b71Sopenharmony_ci 3367e41f4b71Sopenharmony_ci```ts 3368e41f4b71Sopenharmony_ciimport { LengthMetrics } from '@kit.ArkUI'; 3369e41f4b71Sopenharmony_ciimport { TextModifier } from '@ohos.arkui.modifier'; 3370e41f4b71Sopenharmony_ci 3371e41f4b71Sopenharmony_ciclass MainTitleTextModfier extends TextModifier { 3372e41f4b71Sopenharmony_ci useStyle1: boolean = true; 3373e41f4b71Sopenharmony_ci applyNormalAttribute(instance: TextModifier): void { 3374e41f4b71Sopenharmony_ci if (this.useStyle1) { 3375e41f4b71Sopenharmony_ci console.log(`testTag mainTitle use style1`); 3376e41f4b71Sopenharmony_ci instance.fontColor('#FFFFC000') 3377e41f4b71Sopenharmony_ci instance.fontSize(35) 3378e41f4b71Sopenharmony_ci instance.fontWeight(FontWeight.Bolder) 3379e41f4b71Sopenharmony_ci instance.fontStyle(FontStyle.Normal) 3380e41f4b71Sopenharmony_ci instance.textShadow({radius: 5, offsetX: 9}) 3381e41f4b71Sopenharmony_ci } else { 3382e41f4b71Sopenharmony_ci console.log(`testTag mainTitle use style2`); 3383e41f4b71Sopenharmony_ci instance.fontColor('#FF23A98D') 3384e41f4b71Sopenharmony_ci instance.fontSize(20) 3385e41f4b71Sopenharmony_ci instance.heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 3386e41f4b71Sopenharmony_ci instance.fontWeight(FontWeight.Lighter) 3387e41f4b71Sopenharmony_ci instance.fontStyle(FontStyle.Italic) 3388e41f4b71Sopenharmony_ci instance.textShadow({radius: 3, offsetX: 3}) 3389e41f4b71Sopenharmony_ci } 3390e41f4b71Sopenharmony_ci } 3391e41f4b71Sopenharmony_ci} 3392e41f4b71Sopenharmony_ci 3393e41f4b71Sopenharmony_ciclass SubTitleTextModfier extends TextModifier { 3394e41f4b71Sopenharmony_ci useStyle1: boolean = true; 3395e41f4b71Sopenharmony_ci applyNormalAttribute(instance: TextModifier): void { 3396e41f4b71Sopenharmony_ci if (this.useStyle1) { 3397e41f4b71Sopenharmony_ci console.log(`testTag subTitle use style1`); 3398e41f4b71Sopenharmony_ci instance.fontColor('#FFFFC000') 3399e41f4b71Sopenharmony_ci instance.fontSize(15) 3400e41f4b71Sopenharmony_ci instance.fontWeight(FontWeight.Bolder) 3401e41f4b71Sopenharmony_ci instance.fontStyle(FontStyle.Normal) 3402e41f4b71Sopenharmony_ci instance.textShadow({radius: 5, offsetX: 9}) 3403e41f4b71Sopenharmony_ci } else { 3404e41f4b71Sopenharmony_ci console.log(`testTag subTitle use style2`); 3405e41f4b71Sopenharmony_ci instance.fontColor('#FF23A98D') 3406e41f4b71Sopenharmony_ci instance.fontSize(10) 3407e41f4b71Sopenharmony_ci instance.fontWeight(FontWeight.Lighter) 3408e41f4b71Sopenharmony_ci instance.fontStyle(FontStyle.Italic) 3409e41f4b71Sopenharmony_ci instance.textShadow({radius: 3, offsetX: 3}) 3410e41f4b71Sopenharmony_ci } 3411e41f4b71Sopenharmony_ci } 3412e41f4b71Sopenharmony_ci} 3413e41f4b71Sopenharmony_ci 3414e41f4b71Sopenharmony_ci@Entry 3415e41f4b71Sopenharmony_ci@Component 3416e41f4b71Sopenharmony_cistruct NavigationExample { 3417e41f4b71Sopenharmony_ci private navPathStack: NavPathStack = new NavPathStack(); 3418e41f4b71Sopenharmony_ci // Assign an initial padding at the start of the title bar. 3419e41f4b71Sopenharmony_ci @State paddingStart: LengthMetrics = LengthMetrics.vp(0); 3420e41f4b71Sopenharmony_ci // Assign an initial padding at the end of the title bar. 3421e41f4b71Sopenharmony_ci @State paddingEnd: LengthMetrics = LengthMetrics.vp(0); 3422e41f4b71Sopenharmony_ci // Main title attribute modifier. 3423e41f4b71Sopenharmony_ci @State mainTitleModifier: MainTitleTextModfier = new MainTitleTextModfier(); 3424e41f4b71Sopenharmony_ci // Subtitle attribute modifier. 3425e41f4b71Sopenharmony_ci @State subTitleModifier: SubTitleTextModfier = new SubTitleTextModfier(); 3426e41f4b71Sopenharmony_ci @State applyModifier: boolean = false; 3427e41f4b71Sopenharmony_ci @State useStyle1: boolean = true; 3428e41f4b71Sopenharmony_ci 3429e41f4b71Sopenharmony_ci @Builder 3430e41f4b71Sopenharmony_ci myRouter(name: string, param?: Object) { 3431e41f4b71Sopenharmony_ci if (name === 'NavDestinationExample') { 3432e41f4b71Sopenharmony_ci NavDestinationExample(); 3433e41f4b71Sopenharmony_ci } 3434e41f4b71Sopenharmony_ci } 3435e41f4b71Sopenharmony_ci 3436e41f4b71Sopenharmony_ci build() { 3437e41f4b71Sopenharmony_ci Navigation(this.navPathStack) { 3438e41f4b71Sopenharmony_ci Column() { 3439e41f4b71Sopenharmony_ci // Switch between padding values for the title bar. 3440e41f4b71Sopenharmony_ci Button('apply padding 32vp') 3441e41f4b71Sopenharmony_ci .onClick(() => { 3442e41f4b71Sopenharmony_ci this.paddingStart = LengthMetrics.vp(32); 3443e41f4b71Sopenharmony_ci this.paddingEnd = LengthMetrics.vp(32); 3444e41f4b71Sopenharmony_ci }) 3445e41f4b71Sopenharmony_ci .margin({top: 70}) 3446e41f4b71Sopenharmony_ci .width(180) 3447e41f4b71Sopenharmony_ci Button('apply padding 20vp') 3448e41f4b71Sopenharmony_ci .onClick(() => { 3449e41f4b71Sopenharmony_ci this.paddingStart = LengthMetrics.vp(20); 3450e41f4b71Sopenharmony_ci this.paddingEnd = LengthMetrics.vp(20); 3451e41f4b71Sopenharmony_ci }) 3452e41f4b71Sopenharmony_ci .margin({top: 40}) 3453e41f4b71Sopenharmony_ci .width(180) 3454e41f4b71Sopenharmony_ci Button('pushPage') 3455e41f4b71Sopenharmony_ci .onClick(() => { 3456e41f4b71Sopenharmony_ci this.navPathStack.pushPath({name: 'NavDestinationExample'}) 3457e41f4b71Sopenharmony_ci }) 3458e41f4b71Sopenharmony_ci .margin({top: 40}) 3459e41f4b71Sopenharmony_ci .width(180) 3460e41f4b71Sopenharmony_ci Row() { 3461e41f4b71Sopenharmony_ci Text(`apply Modifier`) 3462e41f4b71Sopenharmony_ci Toggle({isOn: this.applyModifier, type: ToggleType.Switch}).onChange((isOn: boolean) => { 3463e41f4b71Sopenharmony_ci this.applyModifier = isOn; 3464e41f4b71Sopenharmony_ci }) 3465e41f4b71Sopenharmony_ci } 3466e41f4b71Sopenharmony_ci .padding({ top: 95, left: 5, right: 5 }) 3467e41f4b71Sopenharmony_ci .width(180) 3468e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.SpaceBetween) 3469e41f4b71Sopenharmony_ci Row() { 3470e41f4b71Sopenharmony_ci Text(`use Style1`) 3471e41f4b71Sopenharmony_ci Toggle({isOn: this.useStyle1, type: ToggleType.Switch}).onChange((isOn: boolean) => { 3472e41f4b71Sopenharmony_ci this.mainTitleModifier.useStyle1 = isOn; 3473e41f4b71Sopenharmony_ci this.subTitleModifier.useStyle1 = isOn; 3474e41f4b71Sopenharmony_ci this.useStyle1 = isOn; 3475e41f4b71Sopenharmony_ci }) 3476e41f4b71Sopenharmony_ci } 3477e41f4b71Sopenharmony_ci .padding({ top: 40, left: 5, right: 5 }) 3478e41f4b71Sopenharmony_ci .width(180) 3479e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.SpaceBetween) 3480e41f4b71Sopenharmony_ci } 3481e41f4b71Sopenharmony_ci .width('100%') 3482e41f4b71Sopenharmony_ci .height('100%') 3483e41f4b71Sopenharmony_ci } 3484e41f4b71Sopenharmony_ci .titleMode(NavigationTitleMode.Full) 3485e41f4b71Sopenharmony_ci .title( 3486e41f4b71Sopenharmony_ci {main: "Title", sub: "subTitle"}, 3487e41f4b71Sopenharmony_ci this.applyModifier ? 3488e41f4b71Sopenharmony_ci { 3489e41f4b71Sopenharmony_ci paddingStart: this.paddingStart, 3490e41f4b71Sopenharmony_ci paddingEnd: this.paddingEnd, 3491e41f4b71Sopenharmony_ci mainTitleModifier: this.mainTitleModifier, 3492e41f4b71Sopenharmony_ci subTitleModifier: this.subTitleModifier, 3493e41f4b71Sopenharmony_ci } : { 3494e41f4b71Sopenharmony_ci paddingStart: this.paddingStart, 3495e41f4b71Sopenharmony_ci paddingEnd: this.paddingEnd 3496e41f4b71Sopenharmony_ci }) 3497e41f4b71Sopenharmony_ci .navDestination(this.myRouter) 3498e41f4b71Sopenharmony_ci } 3499e41f4b71Sopenharmony_ci} 3500e41f4b71Sopenharmony_ci 3501e41f4b71Sopenharmony_ci@Component 3502e41f4b71Sopenharmony_ciexport struct NavDestinationExample { 3503e41f4b71Sopenharmony_ci @State menuItems: Array<NavigationMenuItem> = [ 3504e41f4b71Sopenharmony_ci { 3505e41f4b71Sopenharmony_ci value: 'menuItem1', 3506e41f4b71Sopenharmony_ci icon: 'resources/base/media/ic_public_ok.svg', // Icon resource path. 3507e41f4b71Sopenharmony_ci action: () => { 3508e41f4b71Sopenharmony_ci } 3509e41f4b71Sopenharmony_ci } 3510e41f4b71Sopenharmony_ci ] 3511e41f4b71Sopenharmony_ci @State paddingStart: LengthMetrics = LengthMetrics.vp(0); 3512e41f4b71Sopenharmony_ci @State paddingEnd: LengthMetrics = LengthMetrics.vp(0); 3513e41f4b71Sopenharmony_ci // Main title attribute modifier. 3514e41f4b71Sopenharmony_ci @State mainTitleModifier: MainTitleTextModfier = new MainTitleTextModfier(); 3515e41f4b71Sopenharmony_ci // Subtitle attribute modifier. 3516e41f4b71Sopenharmony_ci @State subTitleModifier: SubTitleTextModfier = new SubTitleTextModfier(); 3517e41f4b71Sopenharmony_ci @State applyModifier: boolean = false; 3518e41f4b71Sopenharmony_ci @State useStyle1: boolean = true; 3519e41f4b71Sopenharmony_ci 3520e41f4b71Sopenharmony_ci build() { 3521e41f4b71Sopenharmony_ci NavDestination() { 3522e41f4b71Sopenharmony_ci Column() { 3523e41f4b71Sopenharmony_ci // Switch between padding values for the title bar. 3524e41f4b71Sopenharmony_ci Button('apply padding 32vp') 3525e41f4b71Sopenharmony_ci .onClick(() => { 3526e41f4b71Sopenharmony_ci this.paddingStart = LengthMetrics.vp(32); 3527e41f4b71Sopenharmony_ci this.paddingEnd = LengthMetrics.vp(32); 3528e41f4b71Sopenharmony_ci }) 3529e41f4b71Sopenharmony_ci .margin({top: 150}) 3530e41f4b71Sopenharmony_ci .width(180) 3531e41f4b71Sopenharmony_ci Button('apply padding 20vp') 3532e41f4b71Sopenharmony_ci .onClick(() => { 3533e41f4b71Sopenharmony_ci this.paddingStart = LengthMetrics.vp(20); 3534e41f4b71Sopenharmony_ci this.paddingEnd = LengthMetrics.vp(20); 3535e41f4b71Sopenharmony_ci }) 3536e41f4b71Sopenharmony_ci .margin({top: 40}) 3537e41f4b71Sopenharmony_ci .width(180) 3538e41f4b71Sopenharmony_ci Row() { 3539e41f4b71Sopenharmony_ci Text(`apply Modifier`) 3540e41f4b71Sopenharmony_ci Toggle({isOn: this.applyModifier, type: ToggleType.Switch}).onChange((isOn: boolean) => { 3541e41f4b71Sopenharmony_ci this.applyModifier = isOn; 3542e41f4b71Sopenharmony_ci }) 3543e41f4b71Sopenharmony_ci } 3544e41f4b71Sopenharmony_ci .padding({ top: 95, left: 5, right: 5 }) 3545e41f4b71Sopenharmony_ci .width(180) 3546e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.SpaceBetween) 3547e41f4b71Sopenharmony_ci Row() { 3548e41f4b71Sopenharmony_ci Text(`use Style1`) 3549e41f4b71Sopenharmony_ci Toggle({isOn: this.useStyle1, type: ToggleType.Switch}).onChange((isOn: boolean) => { 3550e41f4b71Sopenharmony_ci this.mainTitleModifier.useStyle1 = isOn; 3551e41f4b71Sopenharmony_ci this.subTitleModifier.useStyle1 = isOn; 3552e41f4b71Sopenharmony_ci this.useStyle1 = isOn; 3553e41f4b71Sopenharmony_ci }) 3554e41f4b71Sopenharmony_ci } 3555e41f4b71Sopenharmony_ci .padding({ top: 40, left: 5, right: 5 }) 3556e41f4b71Sopenharmony_ci .width(180) 3557e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.SpaceBetween) 3558e41f4b71Sopenharmony_ci } 3559e41f4b71Sopenharmony_ci .width('100%') 3560e41f4b71Sopenharmony_ci .height('90%') 3561e41f4b71Sopenharmony_ci } 3562e41f4b71Sopenharmony_ci .hideTitleBar(false) 3563e41f4b71Sopenharmony_ci .title( 3564e41f4b71Sopenharmony_ci {main: "Title", sub: "subTitle"}, 3565e41f4b71Sopenharmony_ci this.applyModifier ? 3566e41f4b71Sopenharmony_ci { 3567e41f4b71Sopenharmony_ci paddingStart: this.paddingStart, 3568e41f4b71Sopenharmony_ci paddingEnd: this.paddingEnd, 3569e41f4b71Sopenharmony_ci mainTitleModifier: this.mainTitleModifier, 3570e41f4b71Sopenharmony_ci subTitleModifier: this.subTitleModifier, 3571e41f4b71Sopenharmony_ci } : { 3572e41f4b71Sopenharmony_ci paddingStart: this.paddingStart, 3573e41f4b71Sopenharmony_ci paddingEnd: this.paddingEnd 3574e41f4b71Sopenharmony_ci }) 3575e41f4b71Sopenharmony_ci .menus(this.menuItems) 3576e41f4b71Sopenharmony_ci } 3577e41f4b71Sopenharmony_ci} 3578e41f4b71Sopenharmony_ci``` 3579e41f4b71Sopenharmony_ci 3580