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