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