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
518## router.pushNamedRoute<sup>10+</sup>
519
520pushNamedRoute(options: NamedRouterOptions): Promise&lt;void&gt;
521
522Navigates to a page using the named route. This API uses a promise to return the result.
523
524**Atomic service API**: This API can be used in atomic services since API version 11.
525
526**System capability**: SystemCapability.ArkUI.ArkUI.Full
527
528**Parameters**
529
530| Name    | Type                             | Mandatory  | Description       |
531| ------- | ------------------------------- | ---- | --------- |
532| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Page routing parameters.|
533
534**Return value**
535
536| Type               | Description       |
537| ------------------- | --------- |
538| Promise&lt;void&gt; | Promise used to return the result.|
539
540**Error codes**
541
542For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
543> **NOTE**
544>
545> The following error codes returned by this API are all of the string type.
546
547| ID  | Error Message|
548| --------- | ------- |
549| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
550| 100001    | Internal error. |
551| 100003    | Page stack error. Too many pages are pushed. |
552| 100004    | Named route error. The named route does not exist. |
553
554**Example**
555
556```ts
557import { BusinessError } from '@kit.BasicServicesKit';
558
559class innerParams {
560  data3:number[]
561
562  constructor(tuple:number[]) {
563    this.data3 = tuple
564  }
565}
566
567class routerParams {
568  data1:string
569  data2:innerParams
570
571  constructor(str:string, tuple:number[]) {
572    this.data1 = str
573    this.data2 = new innerParams(tuple)
574  }
575}
576
577try {
578  router.pushNamedRoute({
579    name: 'myPage',
580    params: new routerParams('message' ,[123,456,789])
581  })
582} catch (err) {
583  console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
584}
585```
586
587For details, see [UI Development-Named Route](../../ui/arkts-routing.md#named-route).
588
589## router.pushNamedRoute<sup>10+</sup>
590
591pushNamedRoute(options: NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
592
593Navigates to a page using the named route. This API uses a promise to return the result.
594
595**Atomic service API**: This API can be used in atomic services since API version 11.
596
597**System capability**: SystemCapability.ArkUI.ArkUI.Full
598
599**Parameters**
600
601| Name    | Type                             | Mandatory  | Description       |
602| ------- | ------------------------------- | ---- | --------- |
603| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Page routing parameters.|
604| callback | AsyncCallback&lt;void&gt;      | Yes  | Callback used to return the result.  |
605
606**Error codes**
607
608For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
609> **NOTE**
610>
611> The following error codes returned by this API are all of the string type.
612
613| ID  | Error Message|
614| --------- | ------- |
615| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
616| 100001    | Internal error. |
617| 100003    | Page stack error. Too many pages are pushed. |
618| 100004    | Named route error. The named route does not exist. |
619
620**Example**
621
622```ts
623class innerParams {
624  data3:number[]
625
626  constructor(tuple:number[]) {
627    this.data3 = tuple
628  }
629}
630
631class routerParams {
632  data1:string
633  data2:innerParams
634
635  constructor(str:string, tuple:number[]) {
636    this.data1 = str
637    this.data2 = new innerParams(tuple)
638  }
639}
640
641router.pushNamedRoute({
642  name: 'myPage',
643  params: new routerParams('message' ,[123,456,789])
644}, (err) => {
645  if (err) {
646    console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`);
647    return;
648  }
649  console.info('pushNamedRoute success');
650})
651```
652## router.pushNamedRoute<sup>10+</sup>
653
654pushNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise&lt;void&gt;
655
656Navigates to a page using the named route. This API uses a promise to return the result.
657
658**Atomic service API**: This API can be used in atomic services since API version 11.
659
660**System capability**: SystemCapability.ArkUI.ArkUI.Full
661
662**Parameters**
663
664| Name    | Type                             | Mandatory  | Description        |
665| ------- | ------------------------------- | ---- | ---------- |
666| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Page routing parameters. |
667| mode    | [RouterMode](#routermode9)      | Yes   | Routing mode.|
668
669**Return value**
670
671| Type               | Description       |
672| ------------------- | --------- |
673| Promise&lt;void&gt; | Promise used to return the result.|
674
675**Error codes**
676
677For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
678> **NOTE**
679>
680> The following error codes returned by this API are all of the string type.
681
682| ID  | Error Message|
683| --------- | ------- |
684| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
685| 100001    | Internal error. |
686| 100003    | Page stack error. Too many pages are pushed. |
687| 100004    | Named route error. The named route does not exist. |
688
689**Example**
690
691```ts
692import { BusinessError } from '@kit.BasicServicesKit';
693
694class innerParams {
695  data3:number[]
696
697  constructor(tuple:number[]) {
698    this.data3 = tuple
699  }
700}
701
702class routerParams {
703  data1:string
704  data2:innerParams
705
706  constructor(str:string, tuple:number[]) {
707    this.data1 = str
708    this.data2 = new innerParams(tuple)
709  }
710}
711
712try {
713  router.pushNamedRoute({
714    name: 'myPage',
715    params: new routerParams('message' ,[123,456,789])
716  }, router.RouterMode.Standard)
717} catch (err) {
718  console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
719}
720```
721
722## router.pushNamedRoute<sup>10+</sup>
723
724pushNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
725
726Navigates to a page using the named route. This API uses a promise to return the result.
727
728**Atomic service API**: This API can be used in atomic services since API version 11.
729
730**System capability**: SystemCapability.ArkUI.ArkUI.Full
731
732**Parameters**
733
734| Name    | Type                             | Mandatory  | Description        |
735| ------- | ------------------------------- | ---- | ---------- |
736| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Page routing parameters. |
737| mode    | [RouterMode](#routermode9)      | Yes   | Routing mode.|
738| callback | AsyncCallback&lt;void&gt;      | Yes  | Callback used to return the result.  |
739
740**Error codes**
741
742For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
743> **NOTE**
744>
745> The following error codes returned by this API are all of the string type.
746
747| ID  | Error Message|
748| --------- | ------- |
749| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
750| 100001    | Internal error. |
751| 100003    | Page stack error. Too many pages are pushed. |
752| 100004    | Named route error. The named route does not exist. |
753
754**Example**
755
756```ts
757class innerParams {
758  data3:number[]
759
760  constructor(tuple:number[]) {
761    this.data3 = tuple
762  }
763}
764
765class routerParams {
766  data1:string
767  data2:innerParams
768
769  constructor(str:string, tuple:number[]) {
770    this.data1 = str
771    this.data2 = new innerParams(tuple)
772  }
773}
774
775router.pushNamedRoute({
776  name: 'myPage',
777  params: new routerParams('message' ,[123,456,789])
778}, router.RouterMode.Standard, (err) => {
779  if (err) {
780    console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`);
781    return;
782  }
783  console.info('pushNamedRoute success');
784})
785```
786
787## router.replaceNamedRoute<sup>10+</sup>
788
789replaceNamedRoute(options: NamedRouterOptions): Promise&lt;void&gt;
790
791Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
792
793**Atomic service API**: This API can be used in atomic services since API version 11.
794
795**System capability**: SystemCapability.ArkUI.ArkUI.Full
796
797**Parameters**
798
799| Name | Type                           | Mandatory| Description              |
800| ------- | ------------------------------- | ---- | ------------------ |
801| options | [NamedRouterOptions](#namedrouteroptions10) | Yes  | Description of the new page.|
802
803**Return value**
804
805| Type               | Description       |
806| ------------------- | --------- |
807| Promise&lt;void&gt; | Promise used to return the result.|
808
809**Error codes**
810
811For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
812> **NOTE**
813>
814> The following error codes returned by this API are all of the string type.
815
816| ID  | Error Message|
817| --------- | ------- |
818| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
819| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
820| 100004    | Named route error. The named route does not exist. |
821
822**Example**
823
824```ts
825import { BusinessError } from '@kit.BasicServicesKit';
826
827class routerParams {
828  data1:string
829
830  constructor(str:string) {
831    this.data1 = str
832  }
833}
834
835try {
836  router.replaceNamedRoute({
837    name: 'myPage',
838    params: new routerParams('message')
839  })
840} catch (err) {
841  console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
842}
843```
844
845## router.replaceNamedRoute<sup>10+</sup>
846
847replaceNamedRoute(options: NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
848
849Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
850
851**Atomic service API**: This API can be used in atomic services since API version 11.
852
853**System capability**: SystemCapability.ArkUI.ArkUI.Full
854
855**Parameters**
856
857| Name | Type                           | Mandatory| Description              |
858| ------- | ------------------------------- | ---- | ------------------ |
859| options | [NamedRouterOptions](#namedrouteroptions10) | Yes  | Description of the new page.|
860| callback | AsyncCallback&lt;void&gt;      | Yes  | Callback used to return the result.  |
861
862**Error codes**
863
864For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
865> **NOTE**
866>
867> The following error codes returned by this API are all of the string type.
868
869| ID  | Error Message|
870| --------- | ------- |
871| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
872| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
873| 100004    | Named route error. The named route does not exist. |
874
875**Example**
876
877```ts
878class routerParams {
879  data1:string
880
881  constructor(str:string) {
882    this.data1 = str
883  }
884}
885
886router.replaceNamedRoute({
887  name: 'myPage',
888  params: new routerParams('message')
889}, (err) => {
890  if (err) {
891    console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`);
892    return;
893  }
894  console.info('replaceNamedRoute success');
895})
896```
897
898## router.replaceNamedRoute<sup>10+</sup>
899
900replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise&lt;void&gt;
901
902Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
903
904**Atomic service API**: This API can be used in atomic services since API version 11.
905
906**System capability**: SystemCapability.ArkUI.ArkUI.Full
907
908**Parameters**
909
910| Name    | Type                             | Mandatory  | Description        |
911| ------- | ------------------------------- | ---- | ---------- |
912| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Description of the new page. |
913| mode    | [RouterMode](#routermode9)      | Yes   | Routing mode.|
914
915
916**Return value**
917
918| Type               | Description       |
919| ------------------- | --------- |
920| Promise&lt;void&gt; | Promise used to return the result.|
921
922**Error codes**
923
924For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
925> **NOTE**
926>
927> The following error codes returned by this API are all of the string type.
928
929| ID  | Error Message|
930| --------- | ------- |
931| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
932| 100001    | Failed to get the delegate. This error code is thrown only in the standard system. |
933| 100004    | Named route error. The named route does not exist. |
934
935**Example**
936
937```ts
938import { BusinessError } from '@kit.BasicServicesKit';
939
940class routerParams {
941  data1:string
942
943  constructor(str:string) {
944    this.data1 = str
945  }
946}
947
948try {
949  router.replaceNamedRoute({
950    name: 'myPage',
951    params: new routerParams('message')
952  }, router.RouterMode.Standard)
953} catch (err) {
954  console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
955}
956```
957
958## router.replaceNamedRoute<sup>10+</sup>
959
960replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
961
962Replaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
963
964**Atomic service API**: This API can be used in atomic services since API version 11.
965
966**System capability**: SystemCapability.ArkUI.ArkUI.Full
967
968**Parameters**
969
970| Name    | Type                             | Mandatory  | Description        |
971| ------- | ------------------------------- | ---- | ---------- |
972| options | [NamedRouterOptions](#namedrouteroptions10) | Yes   | Description of the new page. |
973| mode    | [RouterMode](#routermode9)      | Yes   | Routing mode.|
974| callback | AsyncCallback&lt;void&gt;      | Yes  | Callback used to return the result.  |
975
976**Error codes**
977
978For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
979> **NOTE**
980>
981> The following error codes returned by this API are all of the string type.
982
983| ID  | Error Message|
984| --------- | ------- |
985| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
986| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
987| 100004    | Named route error. The named route does not exist. |
988
989**Example**
990
991```ts
992class routerParams {
993  data1:string
994
995  constructor(str:string) {
996    this.data1 = str
997  }
998}
999
1000router.replaceNamedRoute({
1001  name: 'myPage',
1002  params: new routerParams('message')
1003}, router.RouterMode.Standard, (err) => {
1004  if (err) {
1005    console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`);
1006    return;
1007  }
1008  console.info('replaceNamedRoute success');
1009});
1010
1011```
1012
1013## router.back
1014
1015back(options?: RouterOptions ): void
1016
1017Returns to the previous page or a specified page, which deletes all pages between the current page and the target page.
1018
1019**Atomic service API**: This API can be used in atomic services since API version 11.
1020
1021**System capability**: SystemCapability.ArkUI.ArkUI.Full
1022
1023**Parameters**
1024
1025| Name | Type                           | Mandatory| Description                                                        |
1026| ------- | ------------------------------- | ---- | ------------------------------------------------------------ |
1027| options | [RouterOptions](#routeroptions) | No  | Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the application returns to the previous page, and the page is not rebuilt. The page in the page stack is not reclaimed. It will be reclaimed after being popped up. The **back** API does not work if **url** is set to a slash (/).|
1028
1029**Example**
1030
1031```ts
1032router.back({url:'pages/detail'});
1033```
1034
1035## router.back<sup>12+</sup>
1036
1037back(index: number, params?: Object): void;
1038
1039Returns to the specified page, which deletes all pages between the current page and the target page.
1040
1041**Atomic service API**: This API can be used in atomic services since API version 12.
1042
1043**System capability**: SystemCapability.ArkUI.ArkUI.Full
1044
1045**Parameters**
1046
1047| Name    | Type                             | Mandatory  | Description        |
1048| ------- | ------------------------------- | ---- | ---------- |
1049| index | number | Yes   | Index of the target page to navigate to. |
1050| params    | Object      | No   | Parameters carried when returning to the page.|
1051
1052**Example**
1053
1054```ts
1055router.back(1);
1056```
1057```ts
1058router.back(1, {info: 'From Home'}); // Returning with parameters.
1059```
1060
1061## router.clear
1062
1063clear(): void
1064
1065Clears all historical pages in the stack and retains only the current page at the top of the stack.
1066
1067**Atomic service API**: This API can be used in atomic services since API version 11.
1068
1069**System capability**: SystemCapability.ArkUI.ArkUI.Full
1070
1071**Example**
1072
1073```ts
1074router.clear();
1075```
1076
1077## router.getLength
1078
1079getLength(): string
1080
1081Obtains the number of pages in the current stack.
1082
1083**Atomic service API**: This API can be used in atomic services since API version 11.
1084
1085**System capability**: SystemCapability.ArkUI.ArkUI.Full
1086
1087**Return value**
1088
1089| Type    | Description                |
1090| ------ | ------------------ |
1091| string | Number of pages in the stack. The maximum value is **32**.|
1092
1093**Example**
1094
1095```ts
1096let size = router.getLength();
1097console.log('pages stack size = ' + size);
1098```
1099
1100## router.getState
1101
1102getState(): RouterState
1103
1104Obtains state information about the page at the top of the navigation stack.
1105
1106**Atomic service API**: This API can be used in atomic services since API version 11.
1107
1108**System capability**: SystemCapability.ArkUI.ArkUI.Full
1109
1110**Return value**
1111
1112| Type                         | Description     |
1113| --------------------------- | ------- |
1114| [RouterState](#routerstate) | Page routing state.|
1115
1116**Example**
1117
1118```ts
1119let page = router.getState();
1120console.log('current index = ' + page.index);
1121console.log('current name = ' + page.name);
1122console.log('current path = ' + page.path);
1123```
1124
1125## router.getStateByIndex<sup>12+</sup>
1126
1127getStateByIndex(index: number): RouterState | undefined
1128
1129Obtains the status information about a page by its index.
1130
1131**Atomic service API**: This API can be used in atomic services since API version 12.
1132
1133**System capability**: SystemCapability.ArkUI.ArkUI.Full
1134
1135**Parameters**
1136
1137| Name    | Type                             | Mandatory  | Description        |
1138| ------- | ------------------------------- | ---- | ---------- |
1139| index    | number | Yes  | Index of the target page. |
1140
1141**Return value**
1142
1143| Type                         | Description     |
1144| --------------------------- | ------- |
1145| [RouterState](#routerstate) \| undefined | State information about the target page; **undefined** if the specified index does not exist.|
1146
1147**Example**
1148
1149```ts
1150let options:router.RouterState | undefined = router.getStateByIndex(1);
1151if (options != undefined) {
1152  console.log('index = ' + options.index);
1153  console.log('name = ' + options.name);
1154  console.log('path = ' + options.path);
1155  console.log('params = ' + options.params);
1156}
1157```
1158## router.getStateByUrl<sup>12+</sup>
1159
1160getStateByUrl(url: string): Array&lt;RouterState&gt;
1161
1162Obtains the status information about a page by its URL.
1163
1164**Atomic service API**: This API can be used in atomic services since API version 12.
1165
1166**System capability**: SystemCapability.ArkUI.ArkUI.Full
1167
1168**Parameters**
1169
1170| Name    | Type                             | Mandatory  | Description        |
1171| ------- | ------------------------------- | ---- | ---------- |
1172| url    | string | Yes  | URL of the target page. |
1173
1174**Return value**
1175
1176| Type                         | Description     |
1177| --------------------------- | ------- |
1178| Array<[RouterState](#routerstate)> | Page routing state.|
1179
1180**Example**
1181
1182```ts
1183let options:Array<router.RouterState> = router.getStateByUrl('pages/index');
1184for (let i: number = 0; i < options.length; i++) {
1185  console.log('index = ' + options[i].index);
1186  console.log('name = ' + options[i].name);
1187  console.log('path = ' + options[i].path);
1188  console.log('params = ' + options[i].params);
1189}
1190```
1191
1192## RouterState
1193
1194Describes the page routing state.
1195
1196**System capability**: SystemCapability.ArkUI.ArkUI.Full
1197
1198| Name | Type  | Mandatory| Description                                                        |
1199| ----- | ------ | ---- | ------------------------------------------------------------ |
1200| 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.|
1201| 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.|
1202| path  | string | Yes  | Path of the current page.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
1203| 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.                                        |
1204
1205## router.showAlertBeforeBackPage<sup>9+</sup>
1206
1207showAlertBeforeBackPage(options: EnableAlertOptions): void
1208
1209Enables the display of a confirm dialog box before returning to the previous page.
1210
1211**Atomic service API**: This API can be used in atomic services since API version 11.
1212
1213**System capability**: SystemCapability.ArkUI.ArkUI.Full
1214
1215**Parameters**
1216
1217| Name    | Type                                      | Mandatory  | Description       |
1218| ------- | ---------------------------------------- | ---- | --------- |
1219| options | [EnableAlertOptions](#enablealertoptions) | Yes   | Description of the dialog box.|
1220
1221**Error codes**
1222
1223For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
1224
1225| ID  | Error Message|
1226| --------- | ------- |
1227| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
1228| 100001    | Internal error. |
1229
1230**Example**
1231
1232```ts
1233import { BusinessError } from '@kit.BasicServicesKit';
1234
1235try {
1236  router.showAlertBeforeBackPage({
1237    message: 'Message Info'
1238  });
1239} catch(err) {
1240  console.error(`showAlertBeforeBackPage failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
1241}
1242```
1243## EnableAlertOptions
1244
1245Describes the confirm dialog box.
1246
1247**Atomic service API**: This API can be used in atomic services since API version 11.
1248
1249**System capability**: SystemCapability.ArkUI.ArkUI.Full
1250
1251| Name     | Type    | Mandatory  | Description      |
1252| ------- | ------ | ---- | -------- |
1253| message | string | Yes   | Content displayed in the confirm dialog box.|
1254
1255## router.hideAlertBeforeBackPage<sup>9+</sup>
1256
1257hideAlertBeforeBackPage(): void
1258
1259Disables the display of a confirm dialog box before returning to the previous page.
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**Example**
1266
1267```ts
1268router.hideAlertBeforeBackPage();
1269```
1270
1271##  router.getParams
1272
1273getParams(): Object
1274
1275Obtains the parameters passed from the page that initiates redirection to the current page.
1276
1277**Atomic service API**: This API can be used in atomic services since API version 11.
1278
1279**System capability**: SystemCapability.ArkUI.ArkUI.Full
1280
1281**Return value**
1282
1283| Type  | Description                              |
1284| ------ | ---------------------------------- |
1285| object | Parameters passed from the page that initiates redirection to the current page.|
1286
1287**Example**
1288
1289```ts
1290router.getParams();
1291```
1292
1293## RouterOptions
1294
1295Describes the page routing options.
1296
1297**Atomic service API**: This API can be used in atomic services since API version 11.
1298
1299**System capability**: SystemCapability.ArkUI.ArkUI.Lite
1300
1301| Name  | Type  | Mandatory| Description                                                        |
1302| ------ | ------ | ---- | ------------------------------------------------------------ |
1303| 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.|
1304| 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.|
1305| recoverable<sup>14+</sup> | boolean | No  | Whether the corresponding page is recoverable.<br>Default value: **true**, indicating that the page is recoverable<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. |
1306
1307  > **NOTE**
1308  >
1309  > The page routing stack supports a maximum of 32 pages.
1310
1311## RouterMode<sup>9+</sup>
1312
1313Enumerates the routing modes.
1314
1315**Atomic service API**: This API can be used in atomic services since API version 11.
1316
1317**System capability**: SystemCapability.ArkUI.ArkUI.Full
1318
1319| Name    | Description                                                        |
1320| -------- | ------------------------------------------------------------ |
1321| 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.|
1322| 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.|
1323
1324## NamedRouterOptions<sup>10+</sup>
1325
1326Describes the named route options.
1327
1328**Atomic service API**: This API can be used in atomic services since API version 11.
1329
1330**System capability**: SystemCapability.ArkUI.ArkUI.Full
1331
1332| Name  | Type  | Mandatory| Description                                                        |
1333| ------ | ------ | ---- | ------------------------------------------------------------ |
1334| name   | string | Yes  | Name of the target named route.                                |
1335| 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.|
1336| recoverable<sup>14+</sup> | boolean | No  | Whether the corresponding page is recoverable.<br>Default value: **true**, indicating that the page is recoverable<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. |
1337
1338## Examples
1339
1340### JavaScript-based Web-like Development Paradigm
1341
1342The following sample code applies only to JavaScript files, not ArkTS files.
1343
1344<!--code_no_check-->
1345
1346```js
1347// Current page
1348export default {
1349  pushPage() {
1350    router.pushUrl({
1351      url: 'pages/detail/detail',
1352      params: {
1353        data1: 'message'
1354      }
1355    });
1356  }
1357}
1358```
1359<!--code_no_check-->
1360
1361```js
1362// detail page
1363export default {
1364  onInit() {
1365    console.info('showData1:' + router.getParams()['data1']);
1366  }
1367}
1368```
1369
1370### TypeScript-based Declarative Development Paradigm
1371
1372> **NOTE**
1373>
1374> To avoid confusion with **router** instances, 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.
1375
1376```ts
1377// Navigate to the target page through router.pushUrl with the params parameter carried.
1378import { router } from '@kit.ArkUI';
1379import { BusinessError } from '@kit.BasicServicesKit'
1380
1381// Define the class for passing parameters.
1382class innerParams {
1383  array:number[]
1384
1385  constructor(tuple:number[]) {
1386    this.array = tuple
1387  }
1388}
1389
1390class routerParams {
1391  text:string
1392  data:innerParams
1393
1394  constructor(str:string, tuple:number[]) {
1395    this.text = str
1396    this.data = new innerParams(tuple)
1397  }
1398}
1399
1400@Entry
1401@Component
1402struct Index {
1403  async routePage() {
1404    let options:router.RouterOptions = {
1405      url: 'pages/second',
1406      params: new routerParams('This is the value on the first page', [12, 45, 78])
1407    }
1408    try {
1409      // You are advised to use this.getUIContext().getRouter().pushUrl().
1410      await router.pushUrl(options)
1411    } catch (err) {
1412      console.info(` fail callback, code: ${(err as BusinessError).code}, msg: ${(err as BusinessError).message}`)
1413    }
1414  }
1415
1416  build() {
1417    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1418      Text('This is the first page.')
1419        .fontSize(50)
1420        .fontWeight(FontWeight.Bold)
1421      Button() {
1422        Text('next page')
1423          .fontSize(25)
1424          .fontWeight(FontWeight.Bold)
1425      }.type(ButtonType.Capsule)
1426      .margin({ top: 20 })
1427      .backgroundColor('#ccc')
1428      .onClick(() => {
1429        this.routePage()
1430      })
1431    }
1432    .width('100%')
1433    .height('100%')
1434  }
1435}
1436```
1437
1438```ts
1439// Receive the transferred parameters on the second page.
1440import { router } from '@kit.ArkUI';
1441
1442class innerParams {
1443  array:number[]
1444
1445  constructor(tuple:number[]) {
1446    this.array = tuple
1447  }
1448}
1449
1450class routerParams {
1451  text:string
1452  data:innerParams
1453
1454  constructor(str:string, tuple:number[]) {
1455    this.text = str
1456    this.data = new innerParams(tuple)
1457  }
1458}
1459
1460@Entry
1461@Component
1462struct Second {
1463  private content: string = "This is the second page."
1464  // You are advised to use this.getUIContext().getRouter().getParams().
1465  @State text: string = (router.getParams() as routerParams).text
1466  @State data: object = (router.getParams() as routerParams).data
1467  @State secondData: string = ''
1468
1469  build() {
1470    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1471      Text(`${this.content}`)
1472        .fontSize(50)
1473        .fontWeight(FontWeight.Bold)
1474      Text(this.text)
1475        .fontSize(30)
1476        .onClick(() => {
1477          this.secondData = (this.data['array'][1]).toString()
1478        })
1479        .margin({ top: 20 })
1480      Text(`This is the data passed from the first page: ${this.secondData}`)
1481        .fontSize(20)
1482        .margin({ top: 20 })
1483        .backgroundColor('red')
1484    }
1485    .width('100%')
1486    .height('100%')
1487  }
1488}
1489```
1490
1491## router.push<sup>(deprecated)</sup>
1492
1493push(options: RouterOptions): void
1494
1495Navigates to a specified page in the application.
1496
1497This API is deprecated since API version 9. You are advised to use [pushUrl<sup>9+</sup>](#routerpushurl9) instead.
1498
1499**System capability**: SystemCapability.ArkUI.ArkUI.Full
1500
1501**Parameters**
1502
1503| Name    | Type                             | Mandatory  | Description       |
1504| ------- | ------------------------------- | ---- | --------- |
1505| options | [RouterOptions](#routeroptions) | Yes   | Page routing parameters.|
1506
1507
1508**Example**
1509
1510```ts
1511class innerParams {
1512  data3:number[]
1513
1514  constructor(tuple:number[]) {
1515    this.data3 = tuple
1516  }
1517}
1518
1519class routerParams {
1520  data1:string
1521  data2:innerParams
1522
1523  constructor(str:string, tuple:number[]) {
1524    this.data1 = str
1525    this.data2 = new innerParams(tuple)
1526  }
1527}
1528
1529router.push({
1530  url: 'pages/routerpage2',
1531  params: new routerParams('message' ,[123,456,789])
1532});
1533```
1534
1535## router.replace<sup>(deprecated)</sup>
1536
1537replace(options: RouterOptions): void
1538
1539Replaces the current page with another one in the application and destroys the current page.
1540
1541This API is deprecated since API version 9. You are advised to use [replaceUrl<sup>9+</sup>](#routerreplaceurl9) instead.
1542
1543**System capability**: SystemCapability.ArkUI.ArkUI.Lite
1544
1545**Parameters**
1546
1547| Name | Type                           | Mandatory| Description              |
1548| ------- | ------------------------------- | ---- | ------------------ |
1549| options | [RouterOptions](#routeroptions) | Yes  | Description of the new page.|
1550
1551**Example**
1552
1553```ts
1554class routerParams {
1555  data1:string
1556
1557  constructor(str:string) {
1558    this.data1 = str
1559  }
1560}
1561
1562router.replace({
1563  url: 'pages/detail',
1564  params: new routerParams('message')
1565});
1566```
1567
1568## router.enableAlertBeforeBackPage<sup>(deprecated)</sup>
1569
1570enableAlertBeforeBackPage(options: EnableAlertOptions): void
1571
1572Enables the display of a confirm dialog box before returning to the previous page.
1573
1574This API is deprecated since API version 9. You are advised to use [showAlertBeforeBackPage<sup>9+</sup>](#routershowalertbeforebackpage9) instead.
1575
1576**System capability**: SystemCapability.ArkUI.ArkUI.Full
1577
1578**Parameters**
1579
1580| Name    | Type                                      | Mandatory  | Description       |
1581| ------- | ---------------------------------------- | ---- | --------- |
1582| options | [EnableAlertOptions](#enablealertoptions) | Yes   | Description of the dialog box.|
1583
1584**Example**
1585
1586```ts
1587router.enableAlertBeforeBackPage({
1588  message: 'Message Info'
1589});
1590```
1591
1592## router.disableAlertBeforeBackPage<sup>(deprecated)</sup>
1593
1594disableAlertBeforeBackPage(): void
1595
1596Disables the display of a confirm dialog box before returning to the previous page.
1597
1598This API is deprecated since API version 9. You are advised to use [hideAlertBeforeBackPage<sup>9+</sup>](#routerhidealertbeforebackpage9) instead.
1599
1600**System capability**: SystemCapability.ArkUI.ArkUI.Full
1601
1602**Example**
1603
1604```ts
1605router.disableAlertBeforeBackPage();
1606```
1607