1e41f4b71Sopenharmony_ci# Transition from Router to Navigation 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Architecture Differences 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciIn the ArkUI component tree hierarchy, pages that were originally managed by the **Router** module are located beneath the stage management node of the page stack. **Navigation**, as a navigation container component, can be mounted under a single page node and can also be stacked and nested. **Navigation** manages the title bar, content area, and toolbar. The content area is designed to display the content of custom pages and supports page routing capabilities. The design of **Navigation** has the following advantages: 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci1. Explicitly distinguishes the title bar, content area, and toolbar in the API for enhanced management and UX animation flexibility. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci2. Provides the concept of a routing container, allowing you to decide the location of the routing container, and supports display in a modal, sheet, or dialog box. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci3. Integrates UX design and one-time development for multi-device deployment capabilities, with default capabilities for unified title display, page switching, and single or double column adaptation. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci4. Enables flexible page configuration by allowing you to determine the relationship between page aliases and UI through UIBuilder. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci5. Transforms page transition animations into component property animations, offering a richer and more flexible range of transition effects. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci6. Provides an inheritable page stack object for improved page display management. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## Capability Comparison 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| Scenario | Navigation | Router | 24e41f4b71Sopenharmony_ci| --------------------------------------------- | ------------------------------------- | -------------------------------------- | 25e41f4b71Sopenharmony_ci| One-time development for multi-device deployment | Supported. The Auto mode is provided to automatically adapt to single- or double-column layout. | Not supported | 26e41f4b71Sopenharmony_ci| Navigation to a specific page | pushPath & pushDestination | pushUrl & pushNameRoute | 27e41f4b71Sopenharmony_ci| Navigation to a page within an HSP | Supported | Supported | 28e41f4b71Sopenharmony_ci| Navigation to a page within a HAR | Supported | Supported | 29e41f4b71Sopenharmony_ci| Passing parameters during navigation | Supported | Supported | 30e41f4b71Sopenharmony_ci| Obtaining parameters of a specific page | Supported | Not supported | 31e41f4b71Sopenharmony_ci| Type of parameters passed | Passed as an object | Passed as an object, methods not supported within the object| 32e41f4b71Sopenharmony_ci| Navigation result callback | Supported | Supported | 33e41f4b71Sopenharmony_ci| Navigation to a singleton page | Supported | Supported | 34e41f4b71Sopenharmony_ci| Return to a previous page | Supported | Supported | 35e41f4b71Sopenharmony_ci| Passing parameters on returning to a previous page | Supported | Supported | 36e41f4b71Sopenharmony_ci| Returning to a specific route | Supported | Supported | 37e41f4b71Sopenharmony_ci| Dialog box for returning to a previous page | Supported, implemented through route interception | showAlertBeforeBackPage | 38e41f4b71Sopenharmony_ci| Route replacement | replacePath & replacePathByName | replaceUrl & replaceNameRoute | 39e41f4b71Sopenharmony_ci| Clearing the navigation stack | clear | clear | 40e41f4b71Sopenharmony_ci| Removing specific routes from the navigation stack | removeByIndexes & removeByName | Not supported | 41e41f4b71Sopenharmony_ci| Transition animation | Supported | Supported | 42e41f4b71Sopenharmony_ci| Custom transition animation | Supported | Supported, with limited animation types | 43e41f4b71Sopenharmony_ci| Disabling transition animation | Supported, with global or one-time setting | Supported, by setting **duration** in the **pageTransition** API to **0**| 44e41f4b71Sopenharmony_ci| Shared element animation with **geometryTransition** | Supported (shared between **NavDestination** components) | Not supported | 45e41f4b71Sopenharmony_ci| Listening for page lifecycle | UIObserver.on('navDestinationUpdate') | UIObserver.on('routerPageUpdate') | 46e41f4b71Sopenharmony_ci| Obtaining a page stack object | Supported | Not supported | 47e41f4b71Sopenharmony_ci| Route interception | Supported through **setInterception** | Not supported | 48e41f4b71Sopenharmony_ci| Route stack information query | Supported | getState() & getLength() | 49e41f4b71Sopenharmony_ci| Move operations within the navigation stack | moveToTop & moveIndexToTop | Not supported | 50e41f4b71Sopenharmony_ci| Immersive pages | Supported | Not supported; requires window configuration | 51e41f4b71Sopenharmony_ci| Setting the title bar and toolbar| Supported | Not supported | 52e41f4b71Sopenharmony_ci| Modal nested routing | Supported | Not supported | 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci## Transition Guidelines 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci### Page Structure 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciPages managed by **Router** are @Entry decorated components, each of which must be declared in **main_page.json**. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci```json 64e41f4b71Sopenharmony_ci// main_page.json 65e41f4b71Sopenharmony_ci{ 66e41f4b71Sopenharmony_ci "src": [ 67e41f4b71Sopenharmony_ci "pages/Index", 68e41f4b71Sopenharmony_ci "pages/pageOne", 69e41f4b71Sopenharmony_ci "pages/pageTwo" 70e41f4b71Sopenharmony_ci ] 71e41f4b71Sopenharmony_ci} 72e41f4b71Sopenharmony_ci``` 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciThe following is an example of a page managed by **Router**. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci```ts 77e41f4b71Sopenharmony_ci// index.ets 78e41f4b71Sopenharmony_ciimport { router } from '@kit.ArkUI'; 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci@Entry 81e41f4b71Sopenharmony_ci@Component 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_cistruct Index { 84e41f4b71Sopenharmony_ci @State message: string = 'Hello World'; 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci build() { 87e41f4b71Sopenharmony_ci Row() { 88e41f4b71Sopenharmony_ci Column() { 89e41f4b71Sopenharmony_ci Text(this.message) 90e41f4b71Sopenharmony_ci .fontSize(50) 91e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 92e41f4b71Sopenharmony_ci Button('router to pageOne', { stateEffect: true, type: ButtonType.Capsule }) 93e41f4b71Sopenharmony_ci .width('80%') 94e41f4b71Sopenharmony_ci .height(40) 95e41f4b71Sopenharmony_ci .margin(20) 96e41f4b71Sopenharmony_ci .onClick(() => { 97e41f4b71Sopenharmony_ci router.pushUrl({ 98e41f4b71Sopenharmony_ci url: 'pages/pageOne' // Target URL. 99e41f4b71Sopenharmony_ci }, router.RouterMode.Standard, (err) => { 100e41f4b71Sopenharmony_ci if (err) { 101e41f4b71Sopenharmony_ci console.error(Invoke pushUrl failed, code is ${err.code}, message is ${err.message}); 102e41f4b71Sopenharmony_ci return; 103e41f4b71Sopenharmony_ci } 104e41f4b71Sopenharmony_ci console.info('Invoke pushUrl succeeded.'); 105e41f4b71Sopenharmony_ci }) 106e41f4b71Sopenharmony_ci }) 107e41f4b71Sopenharmony_ci } 108e41f4b71Sopenharmony_ci .width('100%') 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci .height('100%') 111e41f4b71Sopenharmony_ci } 112e41f4b71Sopenharmony_ci} 113e41f4b71Sopenharmony_ci``` 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci```ts 116e41f4b71Sopenharmony_ci// pageOne.ets 117e41f4b71Sopenharmony_ciimport { router } from '@kit.ArkUI'; 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci@entry 120e41f4b71Sopenharmony_ci@Component 121e41f4b71Sopenharmony_cistruct pageOne { 122e41f4b71Sopenharmony_ci @State message: string = 'This is pageOne'; 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci build() { 125e41f4b71Sopenharmony_ci Row() { 126e41f4b71Sopenharmony_ci Column() { 127e41f4b71Sopenharmony_ci Text(this.message) 128e41f4b71Sopenharmony_ci .fontSize(50) 129e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 130e41f4b71Sopenharmony_ci Button('router back to Index', { stateEffect: true, type: ButtonType.Capsule }) 131e41f4b71Sopenharmony_ci .width('80%') 132e41f4b71Sopenharmony_ci .height(40) 133e41f4b71Sopenharmony_ci .margin(20) 134e41f4b71Sopenharmony_ci .onClick(() => { 135e41f4b71Sopenharmony_ci router.back(); 136e41f4b71Sopenharmony_ci }) 137e41f4b71Sopenharmony_ci } 138e41f4b71Sopenharmony_ci .width('100%') 139e41f4b71Sopenharmony_ci } 140e41f4b71Sopenharmony_ci .height('100%') 141e41f4b71Sopenharmony_ci } 142e41f4b71Sopenharmony_ci} 143e41f4b71Sopenharmony_ci``` 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciPages using **Navigation** are divided into navigation pages and subpages. The navigation page, also known as a NavBar, is a child component of **Navigation**, while subpages are child components of **NavDestination**. 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ciThe following is an example of the navigation page using **Navigation**. 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci```ts 150e41f4b71Sopenharmony_ci// index.ets 151e41f4b71Sopenharmony_ci@Entry 152e41f4b71Sopenharmony_ci@Component 153e41f4b71Sopenharmony_cistruct Index { 154e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci build() { 157e41f4b71Sopenharmony_ci Navigation(this.pathStack) { 158e41f4b71Sopenharmony_ci Column() { 159e41f4b71Sopenharmony_ci Button('Push PageOne', { stateEffect: true, type: ButtonType.Capsule }) 160e41f4b71Sopenharmony_ci .width('80%') 161e41f4b71Sopenharmony_ci .height(40) 162e41f4b71Sopenharmony_ci .margin(20) 163e41f4b71Sopenharmony_ci .onClick(() => { 164e41f4b71Sopenharmony_ci this.pathStack.pushPathByName('pageOne', null) 165e41f4b71Sopenharmony_ci }) 166e41f4b71Sopenharmony_ci }.width('100%').height('100%') 167e41f4b71Sopenharmony_ci } 168e41f4b71Sopenharmony_ci .title("Navigation") 169e41f4b71Sopenharmony_ci } 170e41f4b71Sopenharmony_ci} 171e41f4b71Sopenharmony_ci``` 172e41f4b71Sopenharmony_ciThe following is an example of a subpage using **Navigation**. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci```ts 175e41f4b71Sopenharmony_ci// PageOne.ets 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci@Builder 178e41f4b71Sopenharmony_ciexport function PageOneBuilder() { 179e41f4b71Sopenharmony_ci PageOne() 180e41f4b71Sopenharmony_ci} 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci@Component 183e41f4b71Sopenharmony_ciexport struct PageOne { 184e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci build() { 187e41f4b71Sopenharmony_ci NavDestination() { 188e41f4b71Sopenharmony_ci Column() { 189e41f4b71Sopenharmony_ci Button('Back to Home', { stateEffect: true, type: ButtonType.Capsule }) 190e41f4b71Sopenharmony_ci .width('80%') 191e41f4b71Sopenharmony_ci .height(40) 192e41f4b71Sopenharmony_ci .margin(20) 193e41f4b71Sopenharmony_ci .onClick(() => { 194e41f4b71Sopenharmony_ci this.pathStack.clear() 195e41f4b71Sopenharmony_ci }) 196e41f4b71Sopenharmony_ci }.width('100%').height('100%') 197e41f4b71Sopenharmony_ci }.title('PageOne') 198e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 199e41f4b71Sopenharmony_ci this.pathStack = context.pathStack 200e41f4b71Sopenharmony_ci }) 201e41f4b71Sopenharmony_ci } 202e41f4b71Sopenharmony_ci} 203e41f4b71Sopenharmony_ci``` 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ciEach subpage also needs to be configured in the system configuration file **route_map.json** (see [System Routing Table](arkts-navigation-navigation.md#system-routing-table)). 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci```json 208e41f4b71Sopenharmony_ci// Configure {"routerMap": "$profile:route_map"} in the project configuration file module.json5. 209e41f4b71Sopenharmony_ci// route_map.json 210e41f4b71Sopenharmony_ci{ 211e41f4b71Sopenharmony_ci "routerMap": [ 212e41f4b71Sopenharmony_ci { 213e41f4b71Sopenharmony_ci "name": "pageOne", 214e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 215e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 216e41f4b71Sopenharmony_ci "data": { 217e41f4b71Sopenharmony_ci "description": "this is pageOne" 218e41f4b71Sopenharmony_ci } 219e41f4b71Sopenharmony_ci } 220e41f4b71Sopenharmony_ci ] 221e41f4b71Sopenharmony_ci} 222e41f4b71Sopenharmony_ci``` 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci### Route Operations 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciTo use the **Router** for page operations, you must import the **@ohos.router** module. 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci```ts 229e41f4b71Sopenharmony_ciimport { router } from '@kit.ArkUI'; 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci// push page 232e41f4b71Sopenharmony_cirouter.pushUrl({ url:"pages/pageOne", params: null }) 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci// pop page 235e41f4b71Sopenharmony_cirouter.back({ url: "pages/pageOne" }) 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci// replace page 238e41f4b71Sopenharmony_cirouter.replaceUrl({ url: "pages/pageOne" }) 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci// clear all page 241e41f4b71Sopenharmony_cirouter.clear() 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci// Obtain the size of the page stack. 244e41f4b71Sopenharmony_cilet size = router.getLength() 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci// Obtain the page state. 247e41f4b71Sopenharmony_cilet pageState = router.getState() 248e41f4b71Sopenharmony_ci``` 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ciTo use the **Navigation** component for page operations, call APIs of the [NavPathStack](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md#navpathstack10) object. You need to first create a **NavPathStack** object and pass it into **Navigation**. 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci```ts 253e41f4b71Sopenharmony_ci@Entry 254e41f4b71Sopenharmony_ci@Component 255e41f4b71Sopenharmony_cistruct Index { 256e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci build() { 259e41f4b71Sopenharmony_ci // Set NavPathStack and pass it to Navigation. 260e41f4b71Sopenharmony_ci Navigation(this.pathStack) { 261e41f4b71Sopenharmony_ci ... 262e41f4b71Sopenharmony_ci }.width('100%').height('100%') 263e41f4b71Sopenharmony_ci .title("Navigation") 264e41f4b71Sopenharmony_ci } 265e41f4b71Sopenharmony_ci} 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci// push page 269e41f4b71Sopenharmony_cithis.pathStack.pushPath({ name: 'pageOne' }) 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci// pop page 272e41f4b71Sopenharmony_cithis.pathStack.pop() 273e41f4b71Sopenharmony_cithis.pathStack.popToIndex(1) 274e41f4b71Sopenharmony_cithis.pathStack.popToName('pageOne') 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci// replace page 277e41f4b71Sopenharmony_cithis.pathStack.replacePath({ name: 'pageOne' }) 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci// clear all page 280e41f4b71Sopenharmony_cithis.pathStack.clear() 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci// Obtain the size of the page stack. 283e41f4b71Sopenharmony_cilet size = this.pathStack.size() 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci// Remove all pages whose name is PageOne from the stack. 286e41f4b71Sopenharmony_cithis.pathStack.removeByName("pageOne") 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci// Remove the page with the specified index. 289e41f4b71Sopenharmony_cithis.pathStack.removeByIndexes([1,3,5]) 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci// Obtain all page names in the stack. 292e41f4b71Sopenharmony_cithis.pathStack.getAllPathName() 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci// Obtain the parameters of the page whose index is 1. 295e41f4b71Sopenharmony_cithis.pathStack.getParamByIndex(1) 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci// Obtain the parameters of the PageOne page. 298e41f4b71Sopenharmony_cithis.pathStack.getParamByName("pageOne") 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci// Obtain the index set of the PageOne page. 301e41f4b71Sopenharmony_cithis.pathStack.getIndexByName("pageOne") 302e41f4b71Sopenharmony_ci... 303e41f4b71Sopenharmony_ci``` 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**Router** serves as a global module that can be used across any page, whereas **Navigation** operates as a component. If subpages within a **Navigation** component need to perform routing operations, they must access the **NavPathStack** object held by **Navigation**. The following are several methods to obtain the **NavPathStack** object: 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci**Method 1**: Use @Provide and @Consume (this method creates coupling and is not recommended). 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci```ts 310e41f4b71Sopenharmony_ci// Navigation root container 311e41f4b71Sopenharmony_ci@Entry 312e41f4b71Sopenharmony_ci@Component 313e41f4b71Sopenharmony_cistruct Index { 314e41f4b71Sopenharmony_ci // Navigation creates a NavPathStack object decorated by @Provide. 315e41f4b71Sopenharmony_ci @Provide('pathStack') pathStack: NavPathStack 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci build() { 318e41f4b71Sopenharmony_ci Navigation(this.pathStack) { 319e41f4b71Sopenharmony_ci ... 320e41f4b71Sopenharmony_ci }.width('100%').height('100%') 321e41f4b71Sopenharmony_ci } 322e41f4b71Sopenharmony_ci .title("Navigation") 323e41f4b71Sopenharmony_ci } 324e41f4b71Sopenharmony_ci} 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci// Navigation subpage 327e41f4b71Sopenharmony_ci@Component 328e41f4b71Sopenharmony_ciexport struct PageOne { 329e41f4b71Sopenharmony_ci // NavDestination obtains the NavPathStack object through @Consume. 330e41f4b71Sopenharmony_ci @Consume('pathStack') pathStack: NavPathStack; 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci build() { 333e41f4b71Sopenharmony_ci NavDestination() { 334e41f4b71Sopenharmony_ci ... 335e41f4b71Sopenharmony_ci } 336e41f4b71Sopenharmony_ci .title("PageOne") 337e41f4b71Sopenharmony_ci } 338e41f4b71Sopenharmony_ci} 339e41f4b71Sopenharmony_ci``` 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**Method 2**: Use the **OnReady** callback. 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci```ts 344e41f4b71Sopenharmony_ci@Component 345e41f4b71Sopenharmony_ciexport struct PageOne { 346e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci build() { 349e41f4b71Sopenharmony_ci NavDestination() { 350e41f4b71Sopenharmony_ci ... 351e41f4b71Sopenharmony_ci }.title('PageOne') 352e41f4b71Sopenharmony_ci .onReady((context: NavDestinationContext) => { 353e41f4b71Sopenharmony_ci this.pathStack = context.pathStack 354e41f4b71Sopenharmony_ci }) 355e41f4b71Sopenharmony_ci } 356e41f4b71Sopenharmony_ci} 357e41f4b71Sopenharmony_ci``` 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**Method 3**: Call the global AppStorage API. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci```ts 362e41f4b71Sopenharmony_ci@Entry 363e41f4b71Sopenharmony_ci@Component 364e41f4b71Sopenharmony_cistruct Index { 365e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci // Set a NavPathStack object globally. 368e41f4b71Sopenharmony_ci aboutToAppear(): void { 369e41f4b71Sopenharmony_ci AppStorage.setOrCreate("PathStack", this.pathStack) 370e41f4b71Sopenharmony_ci } 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci build() { 373e41f4b71Sopenharmony_ci Navigation(this.pathStack) { 374e41f4b71Sopenharmony_ci ... 375e41f4b71Sopenharmony_ci }.width('100%').height('100%') 376e41f4b71Sopenharmony_ci } 377e41f4b71Sopenharmony_ci .title("Navigation") 378e41f4b71Sopenharmony_ci } 379e41f4b71Sopenharmony_ci} 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci// Navigation subpage 382e41f4b71Sopenharmony_ci@Component 383e41f4b71Sopenharmony_ciexport struct PageOne { 384e41f4b71Sopenharmony_ci // The subpage obtains the global NavPathStack object. 385e41f4b71Sopenharmony_ci pathStack: NavPathStack = AppStorage.get("PathStack") as NavPathStack 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci build() { 388e41f4b71Sopenharmony_ci NavDestination() { 389e41f4b71Sopenharmony_ci ... 390e41f4b71Sopenharmony_ci } 391e41f4b71Sopenharmony_ci .title("PageOne") 392e41f4b71Sopenharmony_ci } 393e41f4b71Sopenharmony_ci} 394e41f4b71Sopenharmony_ci``` 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci**Method 4**: Call the custom component query API. For details, see [queryNavigationInfo](../reference/apis-arkui/arkui-ts/ts-custom-component-api.md#querynavigationinfo12). 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci```ts 399e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'; 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci// Custom component on the subpage 402e41f4b71Sopenharmony_ci@Component 403e41f4b71Sopenharmony_cistruct CustomNode { 404e41f4b71Sopenharmony_ci pathStack : NavPathStack = new NavPathStack() 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci aboutToAppear() { 407e41f4b71Sopenharmony_ci // query navigation info 408e41f4b71Sopenharmony_ci let navigationInfo : NavigationInfo = this.queryNavigationInfo() as NavigationInfo 409e41f4b71Sopenharmony_ci this.pathStack = navigationInfo.pathStack; 410e41f4b71Sopenharmony_ci } 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci build() { 413e41f4b71Sopenharmony_ci Row() { 414e41f4b71Sopenharmony_ci Button('Go to PageTwo') 415e41f4b71Sopenharmony_ci .onClick(()=>{ 416e41f4b71Sopenharmony_ci this.pathStack.pushPath({ name: 'pageTwo' }) 417e41f4b71Sopenharmony_ci }) 418e41f4b71Sopenharmony_ci } 419e41f4b71Sopenharmony_ci } 420e41f4b71Sopenharmony_ci} 421e41f4b71Sopenharmony_ci``` 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci### Lifecycle 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ciThe lifecycle of a **Router** page is managed by universal methods within the @Entry page, which mainly includes the following lifecycle events: 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci```ts 428e41f4b71Sopenharmony_ci// Callback after the page is created and mounted to the tree 429e41f4b71Sopenharmony_ciaboutToAppear(): void { 430e41f4b71Sopenharmony_ci} 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci// Callback before the page is destroyed and unmounted 433e41f4b71Sopenharmony_ciaboutToDisappear(): void { 434e41f4b71Sopenharmony_ci} 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci// Callback when the page is displayed 437e41f4b71Sopenharmony_cionPageShow(): void { 438e41f4b71Sopenharmony_ci} 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci// Callback when the page is hidden 441e41f4b71Sopenharmony_cionPageHide(): void { 442e41f4b71Sopenharmony_ci} 443e41f4b71Sopenharmony_ci``` 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ciThe sequence of these lifecycle events is illustrated in the figure below. 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**Navigation**, as a routing container, hosts its lifecycle within the **NavDestination** component and exposes lifecycle events as component events. 450e41f4b71Sopenharmony_ciFor details about the lifecycle, see [Page Lifecycle](arkts-navigation-navigation.md#page-lifecycle). 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci```ts 453e41f4b71Sopenharmony_ci@Component 454e41f4b71Sopenharmony_cistruct PageOne { 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci aboutToDisappear() { 457e41f4b71Sopenharmony_ci } 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci aboutToAppear() { 460e41f4b71Sopenharmony_ci } 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci build() { 463e41f4b71Sopenharmony_ci NavDestination() { 464e41f4b71Sopenharmony_ci ... 465e41f4b71Sopenharmony_ci } 466e41f4b71Sopenharmony_ci .onWillAppear(()=>{ 467e41f4b71Sopenharmony_ci }) 468e41f4b71Sopenharmony_ci .onAppear(()=>{ 469e41f4b71Sopenharmony_ci }) 470e41f4b71Sopenharmony_ci .onWillShow(()=>{ 471e41f4b71Sopenharmony_ci }) 472e41f4b71Sopenharmony_ci .onShown(()=>{ 473e41f4b71Sopenharmony_ci }) 474e41f4b71Sopenharmony_ci .onWillHide(()=>{ 475e41f4b71Sopenharmony_ci }) 476e41f4b71Sopenharmony_ci .onHidden(()=>{ 477e41f4b71Sopenharmony_ci }) 478e41f4b71Sopenharmony_ci .onWillDisappear(()=>{ 479e41f4b71Sopenharmony_ci }) 480e41f4b71Sopenharmony_ci .onDisAppear(()=>{ 481e41f4b71Sopenharmony_ci }) 482e41f4b71Sopenharmony_ci } 483e41f4b71Sopenharmony_ci} 484e41f4b71Sopenharmony_ci``` 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci### Transition Animation 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ciBoth **Router** and **Navigation** offer built-in system transition animations as well as the capability to customize these animations. 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ciFor **Router**, custom page transition animations are implemented through the universal method **pageTransition()**. For details, see [Page Transition Animation](arkts-page-transition-animation.md). 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ciFor **Navigation**, a routing container component, page transition animations are essentially property animations between components. You can custom page transition animations through the [customNavContentTransition](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md#customnavcontenttransition11) event in **Navigation**. For details, see [Customizing a Transition](arkts-navigation-navigation.md#customizing-a-transition). (Note: Dialog-type pages currently do not have transition animations.) 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci### Shared Element Transition 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ciTo animate shared elements during page transitions with **Router**, use the **sharedTransition** API. For details, see 497e41f4b71Sopenharmony_ci[Shared Element Transition (sharedTransition)](../reference/apis-arkui/arkui-ts/ts-transition-animation-shared-elements.md). 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciTo animate shared elements during page transitions with **Navigation**, use the **geometryTransition** API. For details, see [Defining a Shared Element Transition](arkts-navigation-navigation.md#defining-a-shared-element-transition). 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci### Cross-Package Routing 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ciTo implement cross-package routing, with **Router**, use named routes. 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci1. In the [HAR](../quick-start/har-package.md) or [HSP](../quick-start/in-app-hsp.md) you want to navigate to, name the @Entry decorated custom component in [EntryOptions](../quick-start/arkts-create-custom-components.md#entryoptions10). 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci ```ts 508e41f4b71Sopenharmony_ci // library/src/main/ets/pages/Index.ets 509e41f4b71Sopenharmony_ci // library is the new custom name of the shared package. 510e41f4b71Sopenharmony_ci @Entry({ routeName: 'myPage' }) 511e41f4b71Sopenharmony_ci @Component 512e41f4b71Sopenharmony_ci export struct MyComponent { 513e41f4b71Sopenharmony_ci build() { 514e41f4b71Sopenharmony_ci Row() { 515e41f4b71Sopenharmony_ci Column() { 516e41f4b71Sopenharmony_ci Text('Library Page') 517e41f4b71Sopenharmony_ci .fontSize(50) 518e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 519e41f4b71Sopenharmony_ci } 520e41f4b71Sopenharmony_ci .width('100%') 521e41f4b71Sopenharmony_ci } 522e41f4b71Sopenharmony_ci .height('100%') 523e41f4b71Sopenharmony_ci } 524e41f4b71Sopenharmony_ci } 525e41f4b71Sopenharmony_ci ``` 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci2. When the configuration is successful, import the named route page to the page from which you want to navigate and perform the navigation. 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci ```ts 530e41f4b71Sopenharmony_ci import { router } from '@kit.ArkUI'; 531e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 532e41f4b71Sopenharmony_ci import('library/src/main/ets/pages/Index'); // Import the named route page from the library of the shared package. 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci @Entry 535e41f4b71Sopenharmony_ci @Component 536e41f4b71Sopenharmony_ci struct Index { 537e41f4b71Sopenharmony_ci build() { 538e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 539e41f4b71Sopenharmony_ci Text('Hello World') 540e41f4b71Sopenharmony_ci .fontSize(50) 541e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 542e41f4b71Sopenharmony_ci .margin({ top: 20 }) 543e41f4b71Sopenharmony_ci .backgroundColor('#ccc') 544e41f4b71Sopenharmony_ci .onClick(() => { // Click to go to a page in another shared package. 545e41f4b71Sopenharmony_ci try { 546e41f4b71Sopenharmony_ci router.pushNamedRoute({ 547e41f4b71Sopenharmony_ci name: 'myPage', 548e41f4b71Sopenharmony_ci params: { 549e41f4b71Sopenharmony_ci data1: 'message', 550e41f4b71Sopenharmony_ci data2: { 551e41f4b71Sopenharmony_ci data3: [123, 456, 789] 552e41f4b71Sopenharmony_ci } 553e41f4b71Sopenharmony_ci } 554e41f4b71Sopenharmony_ci }) 555e41f4b71Sopenharmony_ci } catch (err) { 556e41f4b71Sopenharmony_ci let message = (err as BusinessError).message 557e41f4b71Sopenharmony_ci let code = (err as BusinessError).code 558e41f4b71Sopenharmony_ci console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`); 559e41f4b71Sopenharmony_ci } 560e41f4b71Sopenharmony_ci }) 561e41f4b71Sopenharmony_ci } 562e41f4b71Sopenharmony_ci .width('100%') 563e41f4b71Sopenharmony_ci .height('100%') 564e41f4b71Sopenharmony_ci } 565e41f4b71Sopenharmony_ci } 566e41f4b71Sopenharmony_ci ``` 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ciAs a routing component, **Navigation** natively supports cross-package navigation. 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci1. Develop a custom component in the HSP (HAR) that you want to navigate to, and declare it as **export**. 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci ```ts 573e41f4b71Sopenharmony_ci @Component 574e41f4b71Sopenharmony_ci export struct PageInHSP { 575e41f4b71Sopenharmony_ci build() { 576e41f4b71Sopenharmony_ci NavDestination() { 577e41f4b71Sopenharmony_ci ... 578e41f4b71Sopenharmony_ci } 579e41f4b71Sopenharmony_ci } 580e41f4b71Sopenharmony_ci } 581e41f4b71Sopenharmony_ci ``` 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci2. Export the component in the **index.ets** file of the HSP (HAR). 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci ```ts 586e41f4b71Sopenharmony_ci export { PageInHSP } from "./src/main/ets/pages/PageInHSP" 587e41f4b71Sopenharmony_ci ``` 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci3. After configuring the project dependencies for the HSP (HAR), import the custom component into **mainPage** and add it to **pageMap** for normal use. 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci ``` 592e41f4b71Sopenharmony_ci // 1. Import the cross-package route page. 593e41f4b71Sopenharmony_ci import { PageInHSP } from 'library/src/main/ets/pages/PageInHSP' 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci @Entry 596e41f4b71Sopenharmony_ci @Component 597e41f4b71Sopenharmony_ci struct mainPage { 598e41f4b71Sopenharmony_ci pageStack: NavPathStack = new NavPathStack() 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci @Builder pageMap(name: string) { 601e41f4b71Sopenharmony_ci if (name === 'PageInHSP') { 602e41f4b71Sopenharmony_ci // 2. Define the route mapping table. 603e41f4b71Sopenharmony_ci PageInHSP() 604e41f4b71Sopenharmony_ci } 605e41f4b71Sopenharmony_ci } 606e41f4b71Sopenharmony_ci build() { 607e41f4b71Sopenharmony_ci Navigation(this.pageStack) { 608e41f4b71Sopenharmony_ci Button("Push HSP Page") 609e41f4b71Sopenharmony_ci .onClick(() => { 610e41f4b71Sopenharmony_ci // 3. Navigate to the page in the HSP. 611e41f4b71Sopenharmony_ci this.pageStack.pushPath({ name: "PageInHSP"}); 612e41f4b71Sopenharmony_ci }) 613e41f4b71Sopenharmony_ci } 614e41f4b71Sopenharmony_ci .navDestination(this.pageMap) 615e41f4b71Sopenharmony_ci } 616e41f4b71Sopenharmony_ci } 617e41f4b71Sopenharmony_ci ``` 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ciIn the above approaches, static dependencies are used for cross-package routing. In large-scale projects, inter-module development generally requires decoupling, which relies on the capability of dynamic routing. 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci### Dynamic Routing 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ciDynamic routing facilitates the reuse of service modules across different products (HAPs) and ensures module decoupling by using a routing table for transitions without interdependencies. It also streamlines the expansion and integration of routing features. 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ciBusiness modules expose a set of pages for various scenarios, which are managed through a unified routing table. Products can register the routing tables of the required modules. 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci**Key Benefits of Dynamic Routing** 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci1. Route definitions can include not only the URL for navigation but also a variety of extended configurations, such as default orientation (landscape or portrait) and authentication requirements, for unified handling during routing. 630e41f4b71Sopenharmony_ci2. Each route is assigned a name, allowing navigation by name rather than by file path, which simplifies the routing process. 631e41f4b71Sopenharmony_ci3. Pages can be loaded using dynamic import (lazy loading), preventing the initial page from loading a large amount of code that could cause lag. 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci**Implementing Dynamic Routing with Router** 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci1. Definition: Add new routes to the routing table -> Bind page files to route names (decorators) -> Associate loading functions with page files (dynamic import functions).<br> 636e41f4b71Sopenharmony_ci2. Registration: Register routes (inject the routing table of dependent modules as needed in the entry ability).<br> 637e41f4b71Sopenharmony_ci3. Navigation: Check the routing table (for registered route names) -> Pre-routing hooks (dynamic import for page loading) -> Perform routing -> Post-routing hooks (common processing, such as tracking). 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**Implementing Dynamic Routing with Navigation** 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci**Solution 1: Custom Routing Table** 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ciThe basic implementation is similar to the aforementioned dynamic routing with **Router**. 644e41f4b71Sopenharmony_ci1. Create a custom routing management module, which is depended on by all modules providing routing pages. 645e41f4b71Sopenharmony_ci2. When constructing the **Navigation** component, inject **NavPathStack** into the routing management module, which then encapsulates **NavPathStack** and provides routing capabilities. 646e41f4b71Sopenharmony_ci3. Instead of providing components directly, each routing page offers a build function wrapped with @build, which is then further encapsulated with **WrappedBuilder** for global encapsulation. 647e41f4b71Sopenharmony_ci4. Each routing page registers its module name, route name, and the **WrappedBuilder**-encapsulated build function into the routing management module. 648e41f4b71Sopenharmony_ci5. The routing management module completes dynamic imports and route transitions as needed. 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**Solution 2: System Routing Table** 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ciSince API version 12, **Navigation** supports a system-wide cross-module routing table solution, which centralizes routing management through individual **router_map.json** files in each service module (HSP/HAR). When a route transition is initiated using **NavPathStack**, the system automatically performs dynamic module loading, component construction, and completes the route transition, achieving module decoupling at the development level. 655e41f4b71Sopenharmony_ciFor details, see [System Routing Table](arkts-navigation-navigation.md#system-routing-table). 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci### Lifecycle Listening 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ciYou can use the observer to register for lifecycle events with the **Router**. For details about the APIs, see [observer.on('routerPageUpdate')](../reference/apis-arkui/js-apis-arkui-observer.md#observeronrouterpageupdate11). 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci```ts 663e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'; 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_cifunction callBackFunc(info: uiObserver.RouterPageInfo) { 666e41f4b71Sopenharmony_ci console.info("RouterPageInfo is : " + JSON.stringify(info)) 667e41f4b71Sopenharmony_ci} 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci// used in ability context. 670e41f4b71Sopenharmony_ciuiObserver.on('routerPageUpdate', this.context, callBackFunc); 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci// used in UIContext. 673e41f4b71Sopenharmony_ciuiObserver.on('routerPageUpdate', this.getUIContext(), callBackFunc); 674e41f4b71Sopenharmony_ci``` 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ciA registered callback is invoked when there is a change in the page state. You can obtain relevant page information such as the page name, index, path, and lifecycle status through the parameters passed to the callback. 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci**Navigation** also allows you to register for lifecycle events through the observer. 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci```ts 681e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 682e41f4b71Sopenharmony_ci ... 683e41f4b71Sopenharmony_ci onWindowStageCreate(windowStage: window.WindowStage): void { 684e41f4b71Sopenharmony_ci ... 685e41f4b71Sopenharmony_ci windowStage.getMainWindow((err: BusinessError, data) => { 686e41f4b71Sopenharmony_ci ... 687e41f4b71Sopenharmony_ci windowClass = data; 688e41f4b71Sopenharmony_ci // Obtain a UIContext instance. 689e41f4b71Sopenharmony_ci let uiContext: UIContext = windowClass.getUIContext(); 690e41f4b71Sopenharmony_ci // Obtain a UIObserver instance. 691e41f4b71Sopenharmony_ci let uiObserver : UIObserver = uiContext.getUIObserver(); 692e41f4b71Sopenharmony_ci // Register a listener for DevNavigation state updates. 693e41f4b71Sopenharmony_ci uiObserver.on("navDestinationUpdate",(info) => { 694e41f4b71Sopenharmony_ci // NavDestinationState.ON_SHOWN = 0, NavDestinationState.ON_HIDE = 1 695e41f4b71Sopenharmony_ci if (info.state == 0) { 696e41f4b71Sopenharmony_ci // Actions to perform when the NavDestination component is shown. 697e41f4b71Sopenharmony_ci console.info('page ON_SHOWN:' + info.name.toString()); 698e41f4b71Sopenharmony_ci } 699e41f4b71Sopenharmony_ci }) 700e41f4b71Sopenharmony_ci }) 701e41f4b71Sopenharmony_ci } 702e41f4b71Sopenharmony_ci} 703e41f4b71Sopenharmony_ci``` 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci### Page Information Query 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ciTo achieve decoupling between custom components and their containing pages, a global API for querying page information is provided within custom components. 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ciWith **Router**, you can use the [queryRouterPageInfo](../reference/apis-arkui/arkui-ts/ts-custom-component-api.md#queryrouterpageinfo12) API to query information about the current page where the custom component resides. The return value includes the following properties, with **pageId** being the unique ID for the page. 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 712e41f4b71Sopenharmony_ci| -------------------- | --------------------------- | ---- | ------------------------------ | 713e41f4b71Sopenharmony_ci| context | UIAbilityContext/ UIContext | Yes | Context information of the page.| 714e41f4b71Sopenharmony_ci| index | number | Yes | Position of the page in the stack. | 715e41f4b71Sopenharmony_ci| name | string | Yes | Name of the page. | 716e41f4b71Sopenharmony_ci| path | string | Yes | Path of the page. | 717e41f4b71Sopenharmony_ci| state | RouterPageState | Yes | Status of the page. | 718e41f4b71Sopenharmony_ci| pageId<sup>12+</sup> | string | Yes | Unique ID of the routerPage page. | 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci```ts 721e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'; 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci// Custom component on the page 724e41f4b71Sopenharmony_ci@Component 725e41f4b71Sopenharmony_cistruct MyComponent { 726e41f4b71Sopenharmony_ci aboutToAppear() { 727e41f4b71Sopenharmony_ci let info: uiObserver.RouterPageInfo | undefined = this.queryRouterPageInfo(); 728e41f4b71Sopenharmony_ci } 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci build() { 731e41f4b71Sopenharmony_ci // ... 732e41f4b71Sopenharmony_ci } 733e41f4b71Sopenharmony_ci} 734e41f4b71Sopenharmony_ci``` 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ciWith **Navigation**, you can use the [queryNavDestinationInfo](../reference/apis-arkui/arkui-ts/ts-custom-component-api.md#querynavdestinationinfo) API to query information about the current page where the custom component resides. The return value includes the following properties, with **navDestinationId** being the unique ID for the page. 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 739e41f4b71Sopenharmony_ci| ----------------------------- | ------------------- | ---- | -------------------------------------------- | 740e41f4b71Sopenharmony_ci| navigationId | ResourceStr | Yes | ID of the **Navigation** component that contains the target **NavDestination** component.| 741e41f4b71Sopenharmony_ci| name | ResourceStr | Yes | Name of the **NavDestination** component. | 742e41f4b71Sopenharmony_ci| state | NavDestinationState | Yes | State of the **NavDestination** component. | 743e41f4b71Sopenharmony_ci| index<sup>12+<sup> | number | Yes | Index of the **NavDestination** component in the navigation stack. | 744e41f4b71Sopenharmony_ci| param<sup>12+<sup> | Object | No | Parameters of the **NavDestination** component. | 745e41f4b71Sopenharmony_ci| navDestinationId<sup>12+<sup> | string | Yes | Unique ID of the **NavDestination** component. | 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci```ts 748e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI'; 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci@Component 751e41f4b71Sopenharmony_ciexport struct NavDestinationExample { 752e41f4b71Sopenharmony_ci build() { 753e41f4b71Sopenharmony_ci NavDestination() { 754e41f4b71Sopenharmony_ci MyComponent() 755e41f4b71Sopenharmony_ci } 756e41f4b71Sopenharmony_ci } 757e41f4b71Sopenharmony_ci} 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci@Component 760e41f4b71Sopenharmony_cistruct MyComponent { 761e41f4b71Sopenharmony_ci navDesInfo: uiObserver.NavDestinationInfo | undefined 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci aboutToAppear() { 764e41f4b71Sopenharmony_ci this.navDesInfo = this.queryNavDestinationInfo(); 765e41f4b71Sopenharmony_ci console.log('get navDestinationInfo: ' + JSON.stringify(this.navDesInfo)) 766e41f4b71Sopenharmony_ci } 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci build() { 769e41f4b71Sopenharmony_ci // ... 770e41f4b71Sopenharmony_ci } 771e41f4b71Sopenharmony_ci} 772e41f4b71Sopenharmony_ci``` 773e41f4b71Sopenharmony_ci 774e41f4b71Sopenharmony_ci### Route Interception 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**Router** does not natively provide route interception, so you must implement it by creating custom routing APIs for redirection and interception logic. 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci**Navigation** provides the [setInterception](../reference/apis-arkui/arkui-ts/ts-basic-components-navigation.md#setinterception12) API for setting callbacks to intercept page navigation. For details, see [Route Interception](arkts-navigation-navigation.md#route-interception). 779