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