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