1# @ohos.router (Page Routing) 2 3The **Router** module provides APIs to access pages through URLs. You can use the APIs to navigate to a specified page in an application, replace the current page with another one in the same application, and return to the previous page or a specified page. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - Page routing APIs can be invoked only after page rendering is complete. Do not call these APIs in **onInit** and **onReady** when the page is still in the rendering phase. 10> 11> - The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](./js-apis-arkui-UIContext.md#uicontext). 12> 13> - Since API version 10, you can use the [getRouter](./js-apis-arkui-UIContext.md#getrouter) API in [UIContext](./js-apis-arkui-UIContext.md#uicontext) to obtain the [Router](./js-apis-arkui-UIContext.md#router) object associated with the current UI context. 14> 15> - To achieve a better transition effect, you are advised to use the [Navigation](../../ui/arkts-navigation-navigation.md) component and [modal transition](../../ui/arkts-modal-transition.md). 16> 17> - When the **pushUrl** or **pushNamedRoute** API uses a callback to return the result, the information obtained from the callback using APIs such as **getLength** may represent an intermediate state of the stack and might not be consistent with the final state. 18 19## Modules to Import 20 21``` 22import { router } from '@kit.ArkUI'; 23``` 24 25## router.pushUrl<sup>9+</sup> 26 27pushUrl(options: RouterOptions): Promise<void> 28 29Navigates to a specified page in the application. 30 31**Atomic service API**: This API can be used in atomic services since API version 11. 32 33**System capability**: SystemCapability.ArkUI.ArkUI.Full 34 35**Parameters** 36 37| Name | Type | Mandatory | Description | 38| ------- | ------------------------------- | ---- | --------- | 39| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | 40 41**Return value** 42 43| Type | Description | 44| ------------------- | --------- | 45| Promise<void> | Promise used to return the result. | 46 47**Error codes** 48 49For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 50 51| ID | Error Message | 52| --------- | ------- | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 54| 100001 | Internal error. | 55| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist. | 56| 100003 | Page stack error. Too many pages are pushed. | 57 58**Example** 59 60```ts 61import { BusinessError } from '@kit.BasicServicesKit'; 62 63class innerParams { 64 data3:number[] 65 66 constructor(tuple:number[]) { 67 this.data3 = tuple 68 } 69} 70 71class routerParams { 72 data1:string 73 data2:innerParams 74 75 constructor(str:string, tuple:number[]) { 76 this.data1 = str 77 this.data2 = new innerParams(tuple) 78 } 79} 80 81try { 82 router.pushUrl({ 83 url: 'pages/routerpage2', 84 params: new routerParams('message' ,[123,456,789]) 85 }) 86} catch (err) { 87 console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 88} 89``` 90 91## router.pushUrl<sup>9+</sup> 92 93pushUrl(options: RouterOptions, callback: AsyncCallback<void>): void 94 95Navigates to a specified page in the application. 96 97**Atomic service API**: This API can be used in atomic services since API version 11. 98 99**System capability**: SystemCapability.ArkUI.ArkUI.Full 100 101**Parameters** 102 103| Name | Type | Mandatory | Description | 104| ------- | ------------------------------- | ---- | --------- | 105| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | 106| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 107 108**Error codes** 109 110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 111 112| ID | Error Message | 113| --------- | ------- | 114| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 115| 100001 | Internal error. | 116| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist. | 117| 100003 | Page stack error. Too many pages are pushed. | 118 119**Example** 120 121```ts 122class innerParams { 123 data3:number[] 124 125 constructor(tuple:number[]) { 126 this.data3 = tuple 127 } 128} 129 130class routerParams { 131 data1:string 132 data2:innerParams 133 134 constructor(str:string, tuple:number[]) { 135 this.data1 = str 136 this.data2 = new innerParams(tuple) 137 } 138} 139 140router.pushUrl({ 141 url: 'pages/routerpage2', 142 params: new routerParams('message' ,[123,456,789]) 143}, (err) => { 144 if (err) { 145 console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); 146 return; 147 } 148 console.info('pushUrl success'); 149}) 150``` 151## router.pushUrl<sup>9+</sup> 152 153pushUrl(options: RouterOptions, mode: RouterMode): Promise<void> 154 155Navigates to a specified page in the application. 156 157**Atomic service API**: This API can be used in atomic services since API version 11. 158 159**System capability**: SystemCapability.ArkUI.ArkUI.Full 160 161**Parameters** 162 163| Name | Type | Mandatory | Description | 164| ------- | ------------------------------- | ---- | ---------- | 165| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | 166| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 167 168**Return value** 169 170| Type | Description | 171| ------------------- | --------- | 172| Promise<void> | Promise used to return the result. | 173 174**Error codes** 175 176For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 177 178| ID | Error Message | 179| --------- | ------- | 180| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 181| 100001 | Internal error. | 182| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist. | 183| 100003 | Page stack error. Too many pages are pushed. | 184 185**Example** 186 187```ts 188import { BusinessError } from '@kit.BasicServicesKit'; 189 190class innerParams { 191 data3:number[] 192 193 constructor(tuple:number[]) { 194 this.data3 = tuple 195 } 196} 197 198class routerParams { 199 data1:string 200 data2:innerParams 201 202 constructor(str:string, tuple:number[]) { 203 this.data1 = str 204 this.data2 = new innerParams(tuple) 205 } 206} 207 208try { 209 router.pushUrl({ 210 url: 'pages/routerpage2', 211 params: new routerParams('message' ,[123,456,789]) 212 }, router.RouterMode.Standard) 213} catch (err) { 214 console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 215} 216``` 217 218## router.pushUrl<sup>9+</sup> 219 220pushUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback<void>): void 221 222Navigates to a specified page in the application. 223 224**Atomic service API**: This API can be used in atomic services since API version 11. 225 226**System capability**: SystemCapability.ArkUI.ArkUI.Full 227 228**Parameters** 229 230| Name | Type | Mandatory | Description | 231| ------- | ------------------------------- | ---- | ---------- | 232| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | 233| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 234| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 235 236**Error codes** 237 238For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 239 240| ID | Error Message | 241| --------- | ------- | 242| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 243| 100001 | Internal error. | 244| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist. | 245| 100003 | Page stack error. Too many pages are pushed. | 246 247**Example** 248 249```ts 250class innerParams { 251 data3:number[] 252 253 constructor(tuple:number[]) { 254 this.data3 = tuple 255 } 256} 257 258class routerParams { 259 data1:string 260 data2:innerParams 261 262 constructor(str:string, tuple:number[]) { 263 this.data1 = str 264 this.data2 = new innerParams(tuple) 265 } 266} 267 268router.pushUrl({ 269 url: 'pages/routerpage2', 270 params: new routerParams('message' ,[123,456,789]) 271}, router.RouterMode.Standard, (err) => { 272 if (err) { 273 console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); 274 return; 275 } 276 console.info('pushUrl success'); 277}) 278``` 279 280## router.replaceUrl<sup>9+</sup> 281 282replaceUrl(options: RouterOptions): Promise<void> 283 284Replaces the current page with another one in the application and destroys the current page. This API cannot be used to configure page transition effects. To configure page transition effects, use the [Navigation](../../ui/arkts-navigation-navigation.md) component. 285 286**Atomic service API**: This API can be used in atomic services since API version 11. 287 288**System capability**: SystemCapability.ArkUI.ArkUI.Lite 289 290**Parameters** 291 292| Name | Type | Mandatory | Description | 293| ------- | ------------------------------- | ---- | ------------------ | 294| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | 295 296**Return value** 297 298| Type | Description | 299| ------------------- | --------- | 300| Promise<void> | Promise used to return the result. | 301 302**Error codes** 303 304For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 305 306| ID | Error Message | 307| --------- | ------- | 308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 309| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 310| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. | 311 312**Example** 313 314```ts 315import { BusinessError } from '@kit.BasicServicesKit'; 316 317class routerParams { 318 data1:string 319 320 constructor(str:string) { 321 this.data1 = str 322 } 323} 324 325try { 326 router.replaceUrl({ 327 url: 'pages/detail', 328 params: new routerParams('message') 329 }) 330} catch (err) { 331 console.error(`replaceUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 332} 333``` 334 335## router.replaceUrl<sup>9+</sup> 336 337replaceUrl(options: RouterOptions, callback: AsyncCallback<void>): void 338 339Replaces the current page with another one in the application and destroys the current page. 340 341**Atomic service API**: This API can be used in atomic services since API version 11. 342 343**System capability**: SystemCapability.ArkUI.ArkUI.Lite 344 345**Parameters** 346 347| Name | Type | Mandatory | Description | 348| ------- | ------------------------------- | ---- | ------------------ | 349| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | 350| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 351 352**Error codes** 353 354For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 355 356| ID | Error Message | 357| --------- | ------- | 358| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 359| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 360| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. | 361 362**Example** 363 364```ts 365class routerParams { 366 data1:string 367 368 constructor(str:string) { 369 this.data1 = str 370 } 371} 372 373router.replaceUrl({ 374 url: 'pages/detail', 375 params: new routerParams('message') 376}, (err) => { 377 if (err) { 378 console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); 379 return; 380 } 381 console.info('replaceUrl success'); 382}) 383``` 384 385## router.replaceUrl<sup>9+</sup> 386 387replaceUrl(options: RouterOptions, mode: RouterMode): Promise<void> 388 389Replaces the current page with another one in the application and destroys the current page. 390 391**Atomic service API**: This API can be used in atomic services since API version 11. 392 393**System capability**: SystemCapability.ArkUI.ArkUI.Lite 394 395**Parameters** 396 397| Name | Type | Mandatory | Description | 398| ------- | ------------------------------- | ---- | ---------- | 399| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | 400| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 401 402 403**Return value** 404 405| Type | Description | 406| ------------------- | --------- | 407| Promise<void> | Promise used to return the result. | 408 409**Error codes** 410 411For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 412 413| ID | Error Message | 414| --------- | ------- | 415| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 416| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 417| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. | 418 419**Example** 420 421```ts 422import { BusinessError } from '@kit.BasicServicesKit'; 423 424class routerParams { 425 data1:string 426 427 constructor(str:string) { 428 this.data1 = str 429 } 430} 431 432try { 433 router.replaceUrl({ 434 url: 'pages/detail', 435 params: new routerParams('message') 436 }, router.RouterMode.Standard) 437} catch (err) { 438 console.error(`replaceUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 439} 440``` 441 442## router.replaceUrl<sup>9+</sup> 443 444replaceUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback<void>): void 445 446Replaces the current page with another one in the application and destroys the current page. 447 448**Atomic service API**: This API can be used in atomic services since API version 11. 449 450**System capability**: SystemCapability.ArkUI.ArkUI.Lite 451 452**Parameters** 453 454| Name | Type | Mandatory | Description | 455| ------- | ------------------------------- | ---- | ---------- | 456| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | 457| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 458| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 459 460**Error codes** 461 462For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 463 464| ID | Error Message | 465| --------- | ------- | 466| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 467| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 468| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. | 469 470**Example** 471 472```ts 473class routerParams { 474 data1:string 475 476 constructor(str:string) { 477 this.data1 = str 478 } 479} 480 481router.replaceUrl({ 482 url: 'pages/detail', 483 params: new routerParams('message') 484}, router.RouterMode.Standard, (err) => { 485 if (err) { 486 console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); 487 return; 488 } 489 console.info('replaceUrl success'); 490}); 491 492``` 493 494## router.pushNamedRoute<sup>10+</sup> 495 496pushNamedRoute(options: NamedRouterOptions): Promise<void> 497 498Navigates to a page using the named route. This API uses a promise to return the result. 499 500**Atomic service API**: This API can be used in atomic services since API version 11. 501 502**System capability**: SystemCapability.ArkUI.ArkUI.Full 503 504**Parameters** 505 506| Name | Type | Mandatory | Description | 507| ------- | ------------------------------- | ---- | --------- | 508| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Page routing parameters. | 509 510**Return value** 511 512| Type | Description | 513| ------------------- | --------- | 514| Promise<void> | Promise used to return the result. | 515 516**Error codes** 517 518For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 519 520| ID | Error Message | 521| --------- | ------- | 522| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 523| 100001 | Internal error. | 524| 100003 | Page stack error. Too many pages are pushed. | 525| 100004 | Named route error. The named route does not exist. | 526 527**Example** 528 529```ts 530import { BusinessError } from '@kit.BasicServicesKit'; 531 532class innerParams { 533 data3:number[] 534 535 constructor(tuple:number[]) { 536 this.data3 = tuple 537 } 538} 539 540class routerParams { 541 data1:string 542 data2:innerParams 543 544 constructor(str:string, tuple:number[]) { 545 this.data1 = str 546 this.data2 = new innerParams(tuple) 547 } 548} 549 550try { 551 router.pushNamedRoute({ 552 name: 'myPage', 553 params: new routerParams('message' ,[123,456,789]) 554 }) 555} catch (err) { 556 console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 557} 558``` 559 560For details, see [UI Development-Named Route](../../ui/arkts-routing.md#named-route). 561 562## router.pushNamedRoute<sup>10+</sup> 563 564pushNamedRoute(options: NamedRouterOptions, callback: AsyncCallback<void>): void 565 566Navigates to a page using the named route. This API uses a promise to return the result. 567 568**Atomic service API**: This API can be used in atomic services since API version 11. 569 570**System capability**: SystemCapability.ArkUI.ArkUI.Full 571 572**Parameters** 573 574| Name | Type | Mandatory | Description | 575| ------- | ------------------------------- | ---- | --------- | 576| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Page routing parameters. | 577| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 578 579**Error codes** 580 581For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 582 583| ID | Error Message | 584| --------- | ------- | 585| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 586| 100001 | Internal error. | 587| 100003 | Page stack error. Too many pages are pushed. | 588| 100004 | Named route error. The named route does not exist. | 589 590**Example** 591 592```ts 593class innerParams { 594 data3:number[] 595 596 constructor(tuple:number[]) { 597 this.data3 = tuple 598 } 599} 600 601class routerParams { 602 data1:string 603 data2:innerParams 604 605 constructor(str:string, tuple:number[]) { 606 this.data1 = str 607 this.data2 = new innerParams(tuple) 608 } 609} 610 611router.pushNamedRoute({ 612 name: 'myPage', 613 params: new routerParams('message' ,[123,456,789]) 614}, (err) => { 615 if (err) { 616 console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`); 617 return; 618 } 619 console.info('pushNamedRoute success'); 620}) 621``` 622## router.pushNamedRoute<sup>10+</sup> 623 624pushNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise<void> 625 626Navigates to a page using the named route. This API uses a promise to return the result. 627 628**Atomic service API**: This API can be used in atomic services since API version 11. 629 630**System capability**: SystemCapability.ArkUI.ArkUI.Full 631 632**Parameters** 633 634| Name | Type | Mandatory | Description | 635| ------- | ------------------------------- | ---- | ---------- | 636| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Page routing parameters. | 637| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 638 639**Return value** 640 641| Type | Description | 642| ------------------- | --------- | 643| Promise<void> | Promise used to return the result. | 644 645**Error codes** 646 647For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 648 649| ID | Error Message | 650| --------- | ------- | 651| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 652| 100001 | Internal error. | 653| 100003 | Page stack error. Too many pages are pushed. | 654| 100004 | Named route error. The named route does not exist. | 655 656**Example** 657 658```ts 659import { BusinessError } from '@kit.BasicServicesKit'; 660 661class innerParams { 662 data3:number[] 663 664 constructor(tuple:number[]) { 665 this.data3 = tuple 666 } 667} 668 669class routerParams { 670 data1:string 671 data2:innerParams 672 673 constructor(str:string, tuple:number[]) { 674 this.data1 = str 675 this.data2 = new innerParams(tuple) 676 } 677} 678 679try { 680 router.pushNamedRoute({ 681 name: 'myPage', 682 params: new routerParams('message' ,[123,456,789]) 683 }, router.RouterMode.Standard) 684} catch (err) { 685 console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 686} 687``` 688 689## router.pushNamedRoute<sup>10+</sup> 690 691pushNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback<void>): void 692 693Navigates to a page using the named route. This API uses a promise to return the result. 694 695**Atomic service API**: This API can be used in atomic services since API version 11. 696 697**System capability**: SystemCapability.ArkUI.ArkUI.Full 698 699**Parameters** 700 701| Name | Type | Mandatory | Description | 702| ------- | ------------------------------- | ---- | ---------- | 703| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Page routing parameters. | 704| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 705| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 706 707**Error codes** 708 709For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 710 711| ID | Error Message | 712| --------- | ------- | 713| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 714| 100001 | Internal error. | 715| 100003 | Page stack error. Too many pages are pushed. | 716| 100004 | Named route error. The named route does not exist. | 717 718**Example** 719 720```ts 721class innerParams { 722 data3:number[] 723 724 constructor(tuple:number[]) { 725 this.data3 = tuple 726 } 727} 728 729class routerParams { 730 data1:string 731 data2:innerParams 732 733 constructor(str:string, tuple:number[]) { 734 this.data1 = str 735 this.data2 = new innerParams(tuple) 736 } 737} 738 739router.pushNamedRoute({ 740 name: 'myPage', 741 params: new routerParams('message' ,[123,456,789]) 742}, router.RouterMode.Standard, (err) => { 743 if (err) { 744 console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`); 745 return; 746 } 747 console.info('pushNamedRoute success'); 748}) 749``` 750 751## router.replaceNamedRoute<sup>10+</sup> 752 753replaceNamedRoute(options: NamedRouterOptions): Promise<void> 754 755Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result. 756 757**Atomic service API**: This API can be used in atomic services since API version 11. 758 759**System capability**: SystemCapability.ArkUI.ArkUI.Full 760 761**Parameters** 762 763| Name | Type | Mandatory | Description | 764| ------- | ------------------------------- | ---- | ------------------ | 765| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Description of the new page. | 766 767**Return value** 768 769| Type | Description | 770| ------------------- | --------- | 771| Promise<void> | Promise used to return the result. | 772 773**Error codes** 774 775For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 776 777| ID | Error Message | 778| --------- | ------- | 779| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 780| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 781| 100004 | Named route error. The named route does not exist. | 782 783**Example** 784 785```ts 786import { BusinessError } from '@kit.BasicServicesKit'; 787 788class routerParams { 789 data1:string 790 791 constructor(str:string) { 792 this.data1 = str 793 } 794} 795 796try { 797 router.replaceNamedRoute({ 798 name: 'myPage', 799 params: new routerParams('message') 800 }) 801} catch (err) { 802 console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 803} 804``` 805 806## router.replaceNamedRoute<sup>10+</sup> 807 808replaceNamedRoute(options: NamedRouterOptions, callback: AsyncCallback<void>): void 809 810Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result. 811 812**Atomic service API**: This API can be used in atomic services since API version 11. 813 814**System capability**: SystemCapability.ArkUI.ArkUI.Full 815 816**Parameters** 817 818| Name | Type | Mandatory | Description | 819| ------- | ------------------------------- | ---- | ------------------ | 820| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Description of the new page. | 821| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 822 823**Error codes** 824 825For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 826 827| ID | Error Message | 828| --------- | ------- | 829| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 830| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 831| 100004 | Named route error. The named route does not exist. | 832 833**Example** 834 835```ts 836class routerParams { 837 data1:string 838 839 constructor(str:string) { 840 this.data1 = str 841 } 842} 843 844router.replaceNamedRoute({ 845 name: 'myPage', 846 params: new routerParams('message') 847}, (err) => { 848 if (err) { 849 console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`); 850 return; 851 } 852 console.info('replaceNamedRoute success'); 853}) 854``` 855 856## router.replaceNamedRoute<sup>10+</sup> 857 858replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise<void> 859 860Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result. 861 862**Atomic service API**: This API can be used in atomic services since API version 11. 863 864**System capability**: SystemCapability.ArkUI.ArkUI.Full 865 866**Parameters** 867 868| Name | Type | Mandatory | Description | 869| ------- | ------------------------------- | ---- | ---------- | 870| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Description of the new page. | 871| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 872 873 874**Return value** 875 876| Type | Description | 877| ------------------- | --------- | 878| Promise<void> | Promise used to return the result. | 879 880**Error codes** 881 882For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 883 884| ID | Error Message | 885| --------- | ------- | 886| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 887| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 888| 100004 | Named route error. The named route does not exist. | 889 890**Example** 891 892```ts 893import { BusinessError } from '@kit.BasicServicesKit'; 894 895class routerParams { 896 data1:string 897 898 constructor(str:string) { 899 this.data1 = str 900 } 901} 902 903try { 904 router.replaceNamedRoute({ 905 name: 'myPage', 906 params: new routerParams('message') 907 }, router.RouterMode.Standard) 908} catch (err) { 909 console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 910} 911``` 912 913## router.replaceNamedRoute<sup>10+</sup> 914 915replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback<void>): void 916 917Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result. 918 919**Atomic service API**: This API can be used in atomic services since API version 11. 920 921**System capability**: SystemCapability.ArkUI.ArkUI.Full 922 923**Parameters** 924 925| Name | Type | Mandatory | Description | 926| ------- | ------------------------------- | ---- | ---------- | 927| options | [NamedRouterOptions](#namedrouteroptions10) | Yes | Description of the new page. | 928| mode | [RouterMode](#routermode9) | Yes | Routing mode. | 929| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 930 931**Error codes** 932 933For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 934 935| ID | Error Message | 936| --------- | ------- | 937| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 938| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. | 939| 100004 | Named route error. The named route does not exist. | 940 941**Example** 942 943```ts 944class routerParams { 945 data1:string 946 947 constructor(str:string) { 948 this.data1 = str 949 } 950} 951 952router.replaceNamedRoute({ 953 name: 'myPage', 954 params: new routerParams('message') 955}, router.RouterMode.Standard, (err) => { 956 if (err) { 957 console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`); 958 return; 959 } 960 console.info('replaceNamedRoute success'); 961}); 962 963``` 964 965## router.back 966 967back(options?: RouterOptions ): void 968 969Returns to the previous page or a specified page. 970 971**Atomic service API**: This API can be used in atomic services since API version 11. 972 973**System capability**: SystemCapability.ArkUI.ArkUI.Full 974 975**Parameters** 976 977| Name | Type | Mandatory | Description | 978| ------- | ------------------------------- | ---- | ------------------------------------------------------------ | 979| options | [RouterOptions](#routeroptions) | No | Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the application returns to the previous page, and the page is not rebuilt. The page in the page stack is not reclaimed. It will be reclaimed after being popped up. The **back** API does not work if **url** is set to a slash (/). | 980 981**Example** 982 983```ts 984router.back({url:'pages/detail'}); 985``` 986 987## router.back<sup>12+</sup> 988 989back(index: number, params?: Object): void; 990 991Returns to the specified page. 992 993**Atomic service API**: This API can be used in atomic services since API version 12. 994 995**System capability**: SystemCapability.ArkUI.ArkUI.Full 996 997**Parameters** 998 999| Name | Type | Mandatory | Description | 1000| ------- | ------------------------------- | ---- | ---------- | 1001| index | number | Yes | Index of the target page to navigate to. | 1002| params | Object | No | Parameters carried when returning to the page. | 1003 1004**Example** 1005 1006```ts 1007router.back(1); 1008``` 1009```ts 1010router.back(1, {info: 'From Home'}); // Returning with parameters. 1011``` 1012 1013## router.clear 1014 1015clear(): void 1016 1017Clears all historical pages in the stack and retains only the current page at the top of the stack. 1018 1019**Atomic service API**: This API can be used in atomic services since API version 11. 1020 1021**System capability**: SystemCapability.ArkUI.ArkUI.Full 1022 1023**Example** 1024 1025```ts 1026router.clear(); 1027``` 1028 1029## router.getLength 1030 1031getLength(): string 1032 1033Obtains the number of pages in the current stack. 1034 1035**Atomic service API**: This API can be used in atomic services since API version 11. 1036 1037**System capability**: SystemCapability.ArkUI.ArkUI.Full 1038 1039**Return value** 1040 1041| Type | Description | 1042| ------ | ------------------ | 1043| string | Number of pages in the stack. The maximum value is **32**. | 1044 1045**Example** 1046 1047```ts 1048let size = router.getLength(); 1049console.log('pages stack size = ' + size); 1050``` 1051 1052## router.getState 1053 1054getState(): RouterState 1055 1056Obtains state information about the page at the top of the navigation stack. 1057 1058**Atomic service API**: This API can be used in atomic services since API version 11. 1059 1060**System capability**: SystemCapability.ArkUI.ArkUI.Full 1061 1062**Return value** 1063 1064| Type | Description | 1065| --------------------------- | ------- | 1066| [RouterState](#routerstate) | Page routing state. | 1067 1068**Example** 1069 1070```ts 1071let page = router.getState(); 1072console.log('current index = ' + page.index); 1073console.log('current name = ' + page.name); 1074console.log('current path = ' + page.path); 1075``` 1076 1077## router.getStateByIndex<sup>12+</sup> 1078 1079getStateByIndex(index: number): RouterState | undefined 1080 1081Obtains the status information about a page by its index. 1082 1083**Atomic service API**: This API can be used in atomic services since API version 12. 1084 1085**System capability**: SystemCapability.ArkUI.ArkUI.Full 1086 1087**Parameters** 1088 1089| Name | Type | Mandatory | Description | 1090| ------- | ------------------------------- | ---- | ---------- | 1091| index | number | Yes | Index of the target page. | 1092 1093**Return value** 1094 1095| Type | Description | 1096| --------------------------- | ------- | 1097| [RouterState](#routerstate) \| undefined | State information about the target page; **undefined** if the specified index does not exist. | 1098 1099**Example** 1100 1101```ts 1102let options:router.RouterState | undefined = router.getStateByIndex(1); 1103if (options != undefined) { 1104 console.log('index = ' + options.index); 1105 console.log('name = ' + options.name); 1106 console.log('path = ' + options.path); 1107 console.log('params = ' + options.params); 1108} 1109``` 1110## router.getStateByUrl<sup>12+</sup> 1111 1112getStateByUrl(url: string): Array<RouterState> 1113 1114Obtains the status information about a page by its URL. 1115 1116**Atomic service API**: This API can be used in atomic services since API version 12. 1117 1118**System capability**: SystemCapability.ArkUI.ArkUI.Full 1119 1120**Parameters** 1121 1122| Name | Type | Mandatory | Description | 1123| ------- | ------------------------------- | ---- | ---------- | 1124| url | string | Yes | URL of the target page. | 1125 1126**Return value** 1127 1128| Type | Description | 1129| --------------------------- | ------- | 1130| Array<[RouterState](#routerstate)> | Page routing state. | 1131 1132**Example** 1133 1134```ts 1135let options:Array<router.RouterState> = router.getStateByUrl('pages/index'); 1136for (let i: number = 0; i < options.length; i++) { 1137 console.log('index = ' + options[i].index); 1138 console.log('name = ' + options[i].name); 1139 console.log('path = ' + options[i].path); 1140 console.log('params = ' + options[i].params); 1141} 1142``` 1143 1144## RouterState 1145 1146Describes the page routing state. 1147 1148**System capability**: SystemCapability.ArkUI.ArkUI.Full 1149 1150| Name | Type | Mandatory | Description | 1151| ----- | ------ | ---- | ------------------------------------------------------------ | 1152| index | number | Yes | Index of the current page in the stack. The index starts from 1 from the bottom to the top of the stack.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1153| name | string | Yes | Name of the current page, that is, the file name.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1154| path | string | Yes | Path of the current page.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1155| params<sup>12+</sup> | Object | Yes | Parameters carried on the current page.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1156 1157## router.showAlertBeforeBackPage<sup>9+</sup> 1158 1159showAlertBeforeBackPage(options: EnableAlertOptions): void 1160 1161Enables the display of a confirm dialog box before returning to the previous page. 1162 1163**Atomic service API**: This API can be used in atomic services since API version 11. 1164 1165**System capability**: SystemCapability.ArkUI.ArkUI.Full 1166 1167**Parameters** 1168 1169| Name | Type | Mandatory | Description | 1170| ------- | ---------------------------------------- | ---- | --------- | 1171| options | [EnableAlertOptions](#enablealertoptions) | Yes | Description of the dialog box. | 1172 1173**Error codes** 1174 1175For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md). 1176 1177| ID | Error Message | 1178| --------- | ------- | 1179| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 1180| 100001 | Internal error. | 1181 1182**Example** 1183 1184```ts 1185import { BusinessError } from '@kit.BasicServicesKit'; 1186 1187try { 1188 router.showAlertBeforeBackPage({ 1189 message: 'Message Info' 1190 }); 1191} catch(err) { 1192 console.error(`showAlertBeforeBackPage failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); 1193} 1194``` 1195## EnableAlertOptions 1196 1197Describes the confirm dialog box. 1198 1199**Atomic service API**: This API can be used in atomic services since API version 11. 1200 1201**System capability**: SystemCapability.ArkUI.ArkUI.Full 1202 1203| Name | Type | Mandatory | Description | 1204| ------- | ------ | ---- | -------- | 1205| message | string | Yes | Content displayed in the confirm dialog box. | 1206 1207## router.hideAlertBeforeBackPage<sup>9+</sup> 1208 1209hideAlertBeforeBackPage(): void 1210 1211Disables the display of a confirm dialog box before returning to the previous page. 1212 1213**Atomic service API**: This API can be used in atomic services since API version 11. 1214 1215**System capability**: SystemCapability.ArkUI.ArkUI.Full 1216 1217**Example** 1218 1219```ts 1220router.hideAlertBeforeBackPage(); 1221``` 1222 1223## router.getParams 1224 1225getParams(): Object 1226 1227Obtains the parameters passed from the page that initiates redirection to the current page. 1228 1229**Atomic service API**: This API can be used in atomic services since API version 11. 1230 1231**System capability**: SystemCapability.ArkUI.ArkUI.Full 1232 1233**Return value** 1234 1235| Type | Description | 1236| ------ | ---------------------------------- | 1237| object | Parameters passed from the page that initiates redirection to the current page. | 1238 1239**Example** 1240 1241``` 1242router.getParams(); 1243``` 1244 1245## RouterOptions 1246 1247Describes the page routing options. 1248 1249**Atomic service API**: This API can be used in atomic services since API version 11. 1250 1251**System capability**: SystemCapability.ArkUI.ArkUI.Lite 1252 1253| Name | Type | Mandatory | Description | 1254| ------ | ------ | ---- | ------------------------------------------------------------ | 1255| url | string | Yes | URL of the target page, in either of the following formats:<br>- Absolute path of the page. The value is available in the pages list in the **config.json** file, for example:<br>- pages/index/index<br>- pages/detail/detail<br>- special value. If the value of url is **"/"**, the application navigates to the home page. By default, the home page is set to the first item in the **src** value array. | 1256| params | Object | No | Data that needs to be passed to the target page during redirection. The received data becomes invalid when the page is switched to another page. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.<br>**NOTE**<br>The **params** parameter cannot pass objects returned by methods and system APIs, for example, **PixelMap** objects defined and returned by media APIs. To pass such objects, extract from them the basic type attributes to be passed, and then construct objects of the object type. | 1257 1258 1259 > **NOTE** 1260 > 1261 > The page routing stack supports a maximum of 32 pages. 1262 1263## RouterMode<sup>9+</sup> 1264 1265Enumerates the routing modes. 1266 1267**Atomic service API**: This API can be used in atomic services since API version 11. 1268 1269**System capability**: SystemCapability.ArkUI.ArkUI.Full 1270 1271| Name | Description | 1272| -------- | ------------------------------------------------------------ | 1273| Standard | Multi-instance mode. It is the default routing mode.<br>The target page is added to the top of the page stack, regardless of whether a page with the same URL exists in the stack.<br>**NOTE**<br>If no routing mode is used, the navigation will be carried out according to the default multi-instance mode. | 1274| Single | Singleton mode.<br>If the URL of the target page already exists in the page stack, the page is moved to the top of the stack.<br>If the URL of the target page does not exist in the page stack, the page is redirected to in multi-instance mode. | 1275 1276## NamedRouterOptions<sup>10+</sup> 1277 1278Describes the named route options. 1279 1280**Atomic service API**: This API can be used in atomic services since API version 11. 1281 1282**System capability**: SystemCapability.ArkUI.ArkUI.Full 1283 1284| Name | Type | Mandatory | Description | 1285| ------ | ------ | ---- | ------------------------------------------------------------ | 1286| name | string | Yes | Name of the target named route. | 1287| params | Object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed. | 1288 1289## Examples 1290 1291### JavaScript-based Web-like Development Paradigm 1292 1293The following sample code applies only to JavaScript files, not ArkTS files. 1294 1295<!--code_no_check--> 1296 1297```js 1298// Current page 1299export default { 1300 pushPage() { 1301 router.pushUrl({ 1302 url: 'pages/detail/detail', 1303 params: { 1304 data1: 'message' 1305 } 1306 }); 1307 } 1308} 1309``` 1310<!--code_no_check--> 1311 1312```js 1313// detail page 1314export default { 1315 onInit() { 1316 console.info('showData1:' + router.getParams()['data1']); 1317 } 1318} 1319``` 1320 1321### TypeScript-based Declarative Development Paradigm 1322 1323```ts 1324// Navigate to the target page through router.pushUrl with the params parameter carried. 1325import { router } from '@kit.ArkUI'; 1326import { BusinessError } from '@kit.BasicServicesKit' 1327 1328// Define the class for passing parameters. 1329class innerParams { 1330 array:number[] 1331 1332 constructor(tuple:number[]) { 1333 this.array = tuple 1334 } 1335} 1336 1337class routerParams { 1338 text:string 1339 data:innerParams 1340 1341 constructor(str:string, tuple:number[]) { 1342 this.text = str 1343 this.data = new innerParams(tuple) 1344 } 1345} 1346 1347@Entry 1348@Component 1349struct Index { 1350 async routePage() { 1351 let options:router.RouterOptions = { 1352 url: 'pages/second', 1353 params: new routerParams ('This is the value on the first page', [12, 45, 78]) 1354 } 1355 try { 1356 await router.pushUrl(options) 1357 } catch (err) { 1358 console.info(` fail callback, code: ${(err as BusinessError).code}, msg: ${(err as BusinessError).message}`) 1359 } 1360 } 1361 1362 build() { 1363 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 1364 Text('This is the first page.') 1365 .fontSize(50) 1366 .fontWeight(FontWeight.Bold) 1367 Button() { 1368 Text('next page') 1369 .fontSize(25) 1370 .fontWeight(FontWeight.Bold) 1371 }.type(ButtonType.Capsule) 1372 .margin({ top: 20 }) 1373 .backgroundColor('#ccc') 1374 .onClick(() => { 1375 this.routePage() 1376 }) 1377 } 1378 .width('100%') 1379 .height('100%') 1380 } 1381} 1382``` 1383 1384```ts 1385// Receive the transferred parameters on the second page. 1386import { router } from '@kit.ArkUI'; 1387 1388class innerParams { 1389 array:number[] 1390 1391 constructor(tuple:number[]) { 1392 this.array = tuple 1393 } 1394} 1395 1396class routerParams { 1397 text:string 1398 data:innerParams 1399 1400 constructor(str:string, tuple:number[]) { 1401 this.text = str 1402 this.data = new innerParams(tuple) 1403 } 1404} 1405 1406@Entry 1407@Component 1408struct Second { 1409 private content: string = "This is the second page." 1410 @State text: string = (router.getParams() as routerParams).text 1411 @State data: object = (router.getParams() as routerParams).data 1412 @State secondData: string = '' 1413 1414 build() { 1415 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 1416 Text(`${this.content}`) 1417 .fontSize(50) 1418 .fontWeight(FontWeight.Bold) 1419 Text(this.text) 1420 .fontSize(30) 1421 .onClick(() => { 1422 this.secondData = (this.data['array'][1]).toString() 1423 }) 1424 .margin({ top: 20 }) 1425 Text(`This is the data passed from the first page: ${this.secondData}`) 1426 .fontSize(20) 1427 .margin({ top: 20 }) 1428 .backgroundColor('red') 1429 } 1430 .width('100%') 1431 .height('100%') 1432 } 1433} 1434``` 1435 1436## router.push<sup>(deprecated)</sup> 1437 1438push(options: RouterOptions): void 1439 1440Navigates to a specified page in the application. 1441 1442This API is deprecated since API version 9. You are advised to use [pushUrl<sup>9+</sup>](#routerpushurl9) instead. 1443 1444**System capability**: SystemCapability.ArkUI.ArkUI.Full 1445 1446**Parameters** 1447 1448| Name | Type | Mandatory | Description | 1449| ------- | ------------------------------- | ---- | --------- | 1450| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | 1451 1452 1453**Example** 1454 1455```ts 1456class innerParams { 1457 data3:number[] 1458 1459 constructor(tuple:number[]) { 1460 this.data3 = tuple 1461 } 1462} 1463 1464class routerParams { 1465 data1:string 1466 data2:innerParams 1467 1468 constructor(str:string, tuple:number[]) { 1469 this.data1 = str 1470 this.data2 = new innerParams(tuple) 1471 } 1472} 1473 1474router.push({ 1475 url: 'pages/routerpage2', 1476 params: new routerParams('message' ,[123,456,789]) 1477}); 1478``` 1479 1480## router.replace<sup>(deprecated)</sup> 1481 1482replace(options: RouterOptions): void 1483 1484Replaces the current page with another one in the application and destroys the current page. 1485 1486This API is deprecated since API version 9. You are advised to use [replaceUrl<sup>9+</sup>](#routerreplaceurl9) instead. 1487 1488**System capability**: SystemCapability.ArkUI.ArkUI.Lite 1489 1490**Parameters** 1491 1492| Name | Type | Mandatory | Description | 1493| ------- | ------------------------------- | ---- | ------------------ | 1494| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | 1495 1496**Example** 1497 1498```ts 1499class routerParams { 1500 data1:string 1501 1502 constructor(str:string) { 1503 this.data1 = str 1504 } 1505} 1506 1507router.replace({ 1508 url: 'pages/detail', 1509 params: new routerParams('message') 1510}); 1511``` 1512 1513## router.enableAlertBeforeBackPage<sup>(deprecated)</sup> 1514 1515enableAlertBeforeBackPage(options: EnableAlertOptions): void 1516 1517Enables the display of a confirm dialog box before returning to the previous page. 1518 1519This API is deprecated since API version 9. You are advised to use [showAlertBeforeBackPage<sup>9+</sup>](#routershowalertbeforebackpage9) instead. 1520 1521**System capability**: SystemCapability.ArkUI.ArkUI.Full 1522 1523**Parameters** 1524 1525| Name | Type | Mandatory | Description | 1526| ------- | ---------------------------------------- | ---- | --------- | 1527| options | [EnableAlertOptions](#enablealertoptions) | Yes | Description of the dialog box. | 1528 1529**Example** 1530 1531```ts 1532router.enableAlertBeforeBackPage({ 1533 message: 'Message Info' 1534}); 1535``` 1536 1537## router.disableAlertBeforeBackPage<sup>(deprecated)</sup> 1538 1539disableAlertBeforeBackPage(): void 1540 1541Disables the display of a confirm dialog box before returning to the previous page. 1542 1543This API is deprecated since API version 9. You are advised to use [hideAlertBeforeBackPage<sup>9+</sup>](#routerhidealertbeforebackpage9) instead. 1544 1545**System capability**: SystemCapability.ArkUI.ArkUI.Full 1546 1547**Example** 1548 1549```ts 1550router.disableAlertBeforeBackPage(); 1551``` 1552