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