• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.router (页面路由)(不推荐)
2<!--Kit: ArkUI-->
3<!--Subsystem: ArkUI-->
4<!--Owner: @mayaolll-->
5<!--Designer: @jiangdayuan-->
6<!--Tester: @lxl007-->
7<!--Adviser: @HelloCrease-->
8
9本模块提供通过不同的url访问不同的页面,包括跳转到应用内的指定页面、同应用内的某个页面替换当前页面、返回上一页面或指定的页面等。
10
11推荐使用[Navigation组件](../../ui/arkts-navigation-navigation.md)作为应用路由框架。
12
13> **说明**
14>
15> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
16>
17> - 页面路由需要在页面渲染完成之后才能调用,在onInit和onReady生命周期中页面还处于渲染阶段,禁止调用页面路由方法。
18>
19> - 本模块功能依赖UI的执行上下文,不可在[UI上下文不明确](../../ui/arkts-global-interface.md#ui上下文不明确)的地方使用,参见[UIContext](arkts-apis-uicontext-uicontext.md)说明。
20>
21> - 如果使用传入callback形式的[pushUrl](arkts-apis-uicontext-router.md#pushurl-1)或[pushNamedRoute](arkts-apis-uicontext-router.md#pushnamedroute-1)接口,callback中通过[getLength](arkts-apis-uicontext-router.md#getlength)等接口获取的栈信息为中间态的栈信息,可能与栈操作完全结束后,再通过[getLength](arkts-apis-uicontext-router.md#getlength)等接口获取的栈信息不一致。
22
23## 导入模块
24
25```
26import { router } from '@kit.ArkUI';
27```
28
29## router.pushUrl<sup>(deprecated)</sup>
30
31pushUrl(options: RouterOptions): Promise&lt;void&gt;
32
33跳转到应用内的指定页面。
34
35> **说明:**
36>
37> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushUrl](arkts-apis-uicontext-router.md#pushurl)。
38>
39> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
40
41**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
42
43**系统能力:** SystemCapability.ArkUI.ArkUI.Full
44
45**参数:**
46
47| 参数名     | 类型                              | 必填   | 说明        |
48| ------- | ------------------------------- | ---- | --------- |
49| options | [RouterOptions](#routeroptions) | 是    | 跳转页面描述信息。 |
50
51**返回值:**
52
53| 类型                | 说明        |
54| ------------------- | --------- |
55| Promise&lt;void&gt; | 异常返回结果。 |
56
57**错误码:**
58
59以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
60> **说明**:
61>
62> 该接口返回的以下错误码均为string类型。
63
64| 错误码ID   | 错误信息 |
65| --------- | ------- |
66| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
67| 100001    | Internal error. |
68| 100002    | Uri error. The URI of the page to redirect is incorrect or does not exist. |
69| 100003    | Page stack error. Too many pages are pushed. |
70
71**示例:**
72
73```ts
74import { BusinessError } from '@kit.BasicServicesKit';
75
76class innerParams {
77  data3: number[];
78
79  constructor(tuple: number[]) {
80    this.data3 = tuple;
81  }
82}
83
84class RouterParams {
85  data1: string;
86  data2: innerParams;
87
88  constructor(str: string, tuple: number[]) {
89    this.data1 = str;
90    this.data2 = new innerParams(tuple);
91  }
92}
93
94router.pushUrl({
95  url: 'pages/routerpage2',
96  params: new RouterParams('message', [123, 456, 789])
97})
98  .then(() => {
99    console.error(`pushUrl finish`);
100  })
101  .catch((err: ESObject) => {
102    console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
103  })
104```
105
106## router.pushUrl<sup>(deprecated)</sup>
107
108pushUrl(options: RouterOptions, callback: AsyncCallback&lt;void&gt;): void
109
110跳转到应用内的指定页面。
111
112> **说明:**
113>
114> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushUrl](arkts-apis-uicontext-router.md#pushurl-1)。
115>
116> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
117
118**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
119
120**系统能力:** SystemCapability.ArkUI.ArkUI.Full
121
122**参数:**
123
124| 参数名     | 类型                              | 必填   | 说明        |
125| ------- | ------------------------------- | ---- | --------- |
126| options | [RouterOptions](#routeroptions) | 是    | 跳转页面描述信息。 |
127| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
128
129**错误码:**
130
131以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
132> **说明**:
133>
134> 该接口返回的以下错误码均为string类型。
135
136| 错误码ID   | 错误信息 |
137| --------- | ------- |
138| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
139| 100001    | Internal error. |
140| 100002    | Uri error. The URI of the page to redirect is incorrect or does not exist. |
141| 100003    | Page stack error. Too many pages are pushed. |
142
143**示例:**
144
145```ts
146class innerParams {
147  data3: number[];
148
149  constructor(tuple: number[]) {
150    this.data3 = tuple;
151  }
152}
153
154class RouterParams {
155  data1: string;
156  data2: innerParams;
157
158  constructor(str: string, tuple: number[]) {
159    this.data1 = str;
160    this.data2 = new innerParams(tuple);
161  }
162}
163
164router.pushUrl({
165  url: 'pages/routerpage2',
166  params: new RouterParams('message', [123, 456, 789])
167}, (err) => {
168  if (err) {
169    console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
170    return;
171  }
172  console.info('pushUrl success');
173})
174```
175## router.pushUrl<sup>(deprecated)</sup>
176
177pushUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt;
178
179跳转到应用内的指定页面。
180
181> **说明:**
182>
183> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushUrl](arkts-apis-uicontext-router.md#pushurl-2)。
184>
185> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
186
187**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
188
189**系统能力:** SystemCapability.ArkUI.ArkUI.Full
190
191**参数:**
192
193| 参数名     | 类型                              | 必填   | 说明         |
194| ------- | ------------------------------- | ---- | ---------- |
195| options | [RouterOptions](#routeroptions) | 是    | 跳转页面描述信息。  |
196| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
197
198**返回值:**
199
200| 类型                | 说明        |
201| ------------------- | --------- |
202| Promise&lt;void&gt; | 异常返回结果。 |
203
204**错误码:**
205
206以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
207> **说明**:
208>
209> 该接口返回的以下错误码均为string类型。
210
211| 错误码ID   | 错误信息 |
212| --------- | ------- |
213| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
214| 100001    | Internal error. |
215| 100002    | Uri error. The URI of the page to redirect is incorrect or does not exist. |
216| 100003    | Page stack error. Too many pages are pushed. |
217
218**示例:**
219
220```ts
221import { BusinessError } from '@kit.BasicServicesKit';
222
223class innerParams {
224  data3: number[];
225
226  constructor(tuple: number[]) {
227    this.data3 = tuple;
228  }
229}
230
231class RouterParams {
232  data1: string;
233  data2: innerParams;
234
235  constructor(str: string, tuple: number[]) {
236    this.data1 = str;
237    this.data2 = new innerParams(tuple);
238  }
239}
240
241router.pushUrl({
242  url: 'pages/routerpage2',
243  params: new RouterParams('message', [123, 456, 789])
244}, router.RouterMode.Standard)
245  .then(() => {
246    console.error(`pushUrl finish`);
247  })
248  .catch((err: ESObject) => {
249    console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
250  })
251```
252
253## router.pushUrl<sup>(deprecated)</sup>
254
255pushUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
256
257跳转到应用内的指定页面。
258
259> **说明:**
260>
261> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushUrl](arkts-apis-uicontext-router.md#pushurl-3)。
262>
263> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
264
265**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
266
267**系统能力:** SystemCapability.ArkUI.ArkUI.Full
268
269**参数:**
270
271| 参数名     | 类型                              | 必填   | 说明         |
272| ------- | ------------------------------- | ---- | ---------- |
273| options | [RouterOptions](#routeroptions) | 是    | 跳转页面描述信息。  |
274| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
275| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
276
277**错误码:**
278
279以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
280> **说明**:
281>
282> 该接口返回的以下错误码均为string类型。
283
284| 错误码ID   | 错误信息 |
285| --------- | ------- |
286| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
287| 100001    | Internal error. |
288| 100002    | Uri error. The URI of the page to redirect is incorrect or does not exist. |
289| 100003    | Page stack error. Too many pages are pushed. |
290
291**示例:**
292
293```ts
294class innerParams {
295  data3: number[];
296
297  constructor(tuple: number[]) {
298    this.data3 = tuple;
299  }
300}
301
302class RouterParams {
303  data1: string;
304  data2: innerParams;
305
306  constructor(str: string, tuple: number[]) {
307    this.data1 = str;
308    this.data2 = new innerParams(tuple);
309  }
310}
311
312router.pushUrl({
313  url: 'pages/routerpage2',
314  params: new RouterParams('message', [123, 456, 789])
315}, router.RouterMode.Standard, (err) => {
316  if (err) {
317    console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
318    return;
319  }
320  console.info('pushUrl success');
321})
322```
323
324## router.replaceUrl<sup>(deprecated)</sup>
325
326replaceUrl(options: RouterOptions): Promise&lt;void&gt;
327
328用应用内的某个页面替换当前页面,并销毁被替换的页面。不支持设置页面转场动效,如需设置,推荐使用[Navigation组件](../../ui/arkts-navigation-navigation.md)。
329
330> **说明:**
331>
332> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceUrl](arkts-apis-uicontext-router.md#replaceurl)。
333>
334> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
335
336**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
337
338**系统能力:** SystemCapability.ArkUI.ArkUI.Lite
339
340**参数:**
341
342| 参数名  | 类型                            | 必填 | 说明               |
343| ------- | ------------------------------- | ---- | ------------------ |
344| options | [RouterOptions](#routeroptions) | 是   | 替换页面描述信息。 |
345
346**返回值:**
347
348| 类型                | 说明        |
349| ------------------- | --------- |
350| Promise&lt;void&gt; | 异常返回结果。 |
351
352**错误码:**
353
354以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
355> **说明**:
356>
357> 该接口返回的以下错误码均为string类型。
358
359| 错误码ID   | 错误信息 |
360| --------- | ------- |
361| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
362| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
363| 200002    | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. |
364
365**示例:**
366
367```ts
368import { BusinessError } from '@kit.BasicServicesKit';
369
370class RouterParams {
371  data1: string;
372
373  constructor(str: string) {
374    this.data1 = str;
375  }
376}
377
378router.replaceUrl({
379  url: 'pages/detail',
380  params: new RouterParams('message')
381})
382  .then(() => {
383    console.error(`replaceUrl finish`);
384  })
385  .catch((err: ESObject) => {
386    console.error(`replaceUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
387  })
388```
389
390## router.replaceUrl<sup>(deprecated)</sup>
391
392replaceUrl(options: RouterOptions, callback: AsyncCallback&lt;void&gt;): void
393
394用应用内的某个页面替换当前页面,并销毁被替换的页面。
395
396> **说明:**
397>
398> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceUrl](arkts-apis-uicontext-router.md#replaceurl-1)。
399>
400> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
401
402**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
403
404**系统能力:** SystemCapability.ArkUI.ArkUI.Lite
405
406**参数:**
407
408| 参数名  | 类型                            | 必填 | 说明               |
409| ------- | ------------------------------- | ---- | ------------------ |
410| options | [RouterOptions](#routeroptions) | 是   | 替换页面描述信息。 |
411| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
412
413**错误码:**
414
415以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
416> **说明**:
417>
418> 该接口返回的以下错误码均为string类型。
419
420| 错误码ID   | 错误信息 |
421| --------- | ------- |
422| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
423| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
424| 200002    | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. |
425
426**示例:**
427
428```ts
429class RouterParams {
430  data1: string;
431
432  constructor(str: string) {
433    this.data1 = str;
434  }
435}
436
437router.replaceUrl({
438  url: 'pages/detail',
439  params: new RouterParams('message')
440}, (err) => {
441  if (err) {
442    console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
443    return;
444  }
445  console.info('replaceUrl success');
446})
447```
448
449## router.replaceUrl<sup>(deprecated)</sup>
450
451replaceUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt;
452
453用应用内的某个页面替换当前页面,并销毁被替换的页面。
454
455> **说明:**
456>
457> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceUrl](arkts-apis-uicontext-router.md#replaceurl-2)。
458>
459> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
460
461**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
462
463**系统能力:** SystemCapability.ArkUI.ArkUI.Lite
464
465**参数:**
466
467| 参数名     | 类型                              | 必填   | 说明         |
468| ------- | ------------------------------- | ---- | ---------- |
469| options | [RouterOptions](#routeroptions) | 是    | 替换页面描述信息。  |
470| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
471
472
473**返回值:**
474
475| 类型                | 说明        |
476| ------------------- | --------- |
477| Promise&lt;void&gt; | 异常返回结果。 |
478
479**错误码:**
480
481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
482> **说明**:
483>
484> 该接口返回的以下错误码均为string类型。
485
486| 错误码ID   | 错误信息 |
487| --------- | ------- |
488| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
489| 100001    | Failed to get the delegate. This error code is thrown only in the standard system. |
490| 200002    | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. |
491
492**示例:**
493
494```ts
495import { BusinessError } from '@kit.BasicServicesKit';
496
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)
509  .then(() => {
510    console.error(`replaceUrl finish`);
511  })
512  .catch((err: ESObject) => {
513    console.error(`replaceUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
514  })
515```
516
517## router.replaceUrl<sup>(deprecated)</sup>
518
519replaceUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
520
521用应用内的某个页面替换当前页面,并销毁被替换的页面。
522
523> **说明:**
524>
525> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceUrl](arkts-apis-uicontext-router.md#replaceurl-3)。
526>
527> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
528
529**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
530
531**系统能力:** SystemCapability.ArkUI.ArkUI.Lite
532
533**参数:**
534
535| 参数名     | 类型                              | 必填   | 说明         |
536| ------- | ------------------------------- | ---- | ---------- |
537| options | [RouterOptions](#routeroptions) | 是    | 替换页面描述信息。  |
538| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
539| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
540
541**错误码:**
542
543以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
544> **说明**:
545>
546> 该接口返回的以下错误码均为string类型。
547
548| 错误码ID   | 错误信息 |
549| --------- | ------- |
550| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
551| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
552| 200002    | Uri error. The URI of the page to be used for replacement is incorrect or does not exist. |
553
554**示例:**
555
556```ts
557class RouterParams {
558  data1: string;
559
560  constructor(str: string) {
561    this.data1 = str;
562  }
563}
564
565router.replaceUrl({
566  url: 'pages/detail',
567  params: new RouterParams('message')
568}, router.RouterMode.Standard, (err) => {
569  if (err) {
570    console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
571    return;
572  }
573  console.info('replaceUrl success');
574});
575```
576
577## router.pushNamedRoute<sup>(deprecated)</sup>
578
579pushNamedRoute(options: NamedRouterOptions): Promise&lt;void&gt;
580
581跳转到指定的命名路由页面。
582
583> **说明:**
584>
585> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushNamedRoute](arkts-apis-uicontext-router.md#pushnamedroute)。
586>
587> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
588
589**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
590
591**系统能力:** SystemCapability.ArkUI.ArkUI.Full
592
593**参数:**
594
595| 参数名     | 类型                              | 必填   | 说明        |
596| ------- | ------------------------------- | ---- | --------- |
597| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 跳转页面描述信息。 |
598
599**返回值:**
600
601| 类型                | 说明        |
602| ------------------- | --------- |
603| Promise&lt;void&gt; | 异常返回结果。 |
604
605**错误码:**
606
607以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
608> **说明**:
609>
610> 该接口返回的以下错误码均为string类型。
611
612| 错误码ID   | 错误信息 |
613| --------- | ------- |
614| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
615| 100001    | Internal error. |
616| 100003    | Page stack error. Too many pages are pushed. |
617| 100004    | Named route error. The named route does not exist. |
618
619**示例:**
620
621```ts
622import { BusinessError } from '@kit.BasicServicesKit';
623
624class innerParams {
625  data3: number[];
626
627  constructor(tuple: number[]) {
628    this.data3 = tuple;
629  }
630}
631
632class RouterParams {
633  data1: string;
634  data2: innerParams;
635
636  constructor(str: string, tuple: number[]) {
637    this.data1 = str;
638    this.data2 = new innerParams(tuple);
639  }
640}
641
642router.pushNamedRoute({
643  name: 'myPage',
644  params: new RouterParams('message', [123, 456, 789])
645})
646  .then(() => {
647    console.error(`pushNamedRoute finish`);
648  })
649  .catch((err: ESObject) => {
650    console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
651  })
652```
653
654详细示例请参考:[UI开发-页面路由](../../ui/arkts-routing.md#命名路由)
655
656## router.pushNamedRoute<sup>(deprecated)</sup>
657
658pushNamedRoute(options: NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
659
660跳转到指定的命名路由页面。
661
662> **说明:**
663>
664> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushNamedRoute](arkts-apis-uicontext-router.md#pushnamedroute-1)。
665>
666> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
667
668**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
669
670**系统能力:** SystemCapability.ArkUI.ArkUI.Full
671
672**参数:**
673
674| 参数名     | 类型                              | 必填   | 说明        |
675| ------- | ------------------------------- | ---- | --------- |
676| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 跳转页面描述信息。 |
677| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
678
679**错误码:**
680
681以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
682> **说明**:
683>
684> 该接口返回的以下错误码均为string类型。
685
686| 错误码ID   | 错误信息 |
687| --------- | ------- |
688| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
689| 100001    | Internal error. |
690| 100003    | Page stack error. Too many pages are pushed. |
691| 100004    | Named route error. The named route does not exist. |
692
693**示例:**
694
695```ts
696class innerParams {
697  data3: number[];
698
699  constructor(tuple: number[]) {
700    this.data3 = tuple;
701  }
702}
703
704class RouterParams {
705  data1: string;
706  data2: innerParams;
707
708  constructor(str: string, tuple: number[]) {
709    this.data1 = str;
710    this.data2 = new innerParams(tuple);
711  }
712}
713
714router.pushNamedRoute({
715  name: 'myPage',
716  params: new RouterParams('message', [123, 456, 789])
717}, (err) => {
718  if (err) {
719    console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`);
720    return;
721  }
722  console.info('pushNamedRoute success');
723})
724```
725## router.pushNamedRoute<sup>(deprecated)</sup>
726
727pushNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise&lt;void&gt;
728
729跳转到指定的命名路由页面。
730
731> **说明:**
732>
733> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushNamedRoute](arkts-apis-uicontext-router.md#pushnamedroute-2)。
734>
735> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
736
737**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
738
739**系统能力:** SystemCapability.ArkUI.ArkUI.Full
740
741**参数:**
742
743| 参数名     | 类型                              | 必填   | 说明         |
744| ------- | ------------------------------- | ---- | ---------- |
745| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 跳转页面描述信息。  |
746| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
747
748**返回值:**
749
750| 类型                | 说明        |
751| ------------------- | --------- |
752| Promise&lt;void&gt; | 异常返回结果。 |
753
754**错误码:**
755
756以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
757> **说明**:
758>
759> 该接口返回的以下错误码均为string类型。
760
761| 错误码ID   | 错误信息 |
762| --------- | ------- |
763| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
764| 100001    | Internal error. |
765| 100003    | Page stack error. Too many pages are pushed. |
766| 100004    | Named route error. The named route does not exist. |
767
768**示例:**
769
770```ts
771import { BusinessError } from '@kit.BasicServicesKit';
772
773class innerParams {
774  data3: number[];
775
776  constructor(tuple: number[]) {
777    this.data3 = tuple;
778  }
779}
780
781class RouterParams {
782  data1: string;
783  data2: innerParams;
784
785  constructor(str: string, tuple: number[]) {
786    this.data1 = str
787    this.data2 = new innerParams(tuple)
788  }
789}
790
791router.pushNamedRoute({
792  name: 'myPage',
793  params: new RouterParams('message', [123, 456, 789])
794}, router.RouterMode.Standard)
795  .then(() => {
796    console.error(`pushNamedRoute finish`);
797  })
798  .catch((err: ESObject) => {
799    console.error(`pushNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
800  })
801```
802
803## router.pushNamedRoute<sup>(deprecated)</sup>
804
805pushNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
806
807跳转到指定的命名路由页面。
808
809> **说明:**
810>
811> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[pushNamedRoute](arkts-apis-uicontext-router.md#pushnamedroute-3)。
812>
813> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
814
815**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
816
817**系统能力:** SystemCapability.ArkUI.ArkUI.Full
818
819**参数:**
820
821| 参数名     | 类型                              | 必填   | 说明         |
822| ------- | ------------------------------- | ---- | ---------- |
823| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 跳转页面描述信息。  |
824| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
825| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
826
827**错误码:**
828
829以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
830> **说明**:
831>
832> 该接口返回的以下错误码均为string类型。
833
834| 错误码ID   | 错误信息 |
835| --------- | ------- |
836| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
837| 100001    | Internal error. |
838| 100003    | Page stack error. Too many pages are pushed. |
839| 100004    | Named route error. The named route does not exist. |
840
841**示例:**
842
843```ts
844class innerParams {
845  data3: number[];
846
847  constructor(tuple: number[]) {
848    this.data3 = tuple;
849  }
850}
851
852class RouterParams {
853  data1: string;
854  data2: innerParams;
855
856  constructor(str: string, tuple: number[]) {
857    this.data1 = str;
858    this.data2 = new innerParams(tuple);
859  }
860}
861
862router.pushNamedRoute({
863  name: 'myPage',
864  params: new RouterParams('message', [123, 456, 789])
865}, router.RouterMode.Standard, (err) => {
866  if (err) {
867    console.error(`pushNamedRoute failed, code is ${err.code}, message is ${err.message}`);
868    return;
869  }
870  console.info('pushNamedRoute success');
871})
872```
873
874## router.replaceNamedRoute<sup>(deprecated)</sup>
875
876replaceNamedRoute(options: NamedRouterOptions): Promise&lt;void&gt;
877
878用指定的命名路由页面替换当前页面,并销毁被替换的页面。
879
880> **说明:**
881>
882> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceNamedRoute](arkts-apis-uicontext-router.md#replacenamedroute)。
883>
884> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
885
886**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
887
888**系统能力:** SystemCapability.ArkUI.ArkUI.Full
889
890**参数:**
891
892| 参数名  | 类型                            | 必填 | 说明               |
893| ------- | ------------------------------- | ---- | ------------------ |
894| options | [NamedRouterOptions](#namedrouteroptions10) | 是   | 替换页面描述信息。 |
895
896**返回值:**
897
898| 类型                | 说明        |
899| ------------------- | --------- |
900| Promise&lt;void&gt; | 异常返回结果。 |
901
902**错误码:**
903
904以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
905> **说明**:
906>
907> 该接口返回的以下错误码均为string类型。
908
909| 错误码ID   | 错误信息 |
910| --------- | ------- |
911| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
912| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
913| 100004    | Named route error. The named route does not exist. |
914
915**示例:**
916
917```ts
918import { BusinessError } from '@kit.BasicServicesKit';
919
920class RouterParams {
921  data1: string;
922
923  constructor(str: string) {
924    this.data1 = str;
925  }
926}
927
928router.replaceNamedRoute({
929  name: 'myPage',
930  params: new RouterParams('message')
931})
932  .then(() => {
933    console.error(`replaceNamedRoute finish`);
934  })
935  .catch((err: ESObject) => {
936    console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
937  })
938```
939
940## router.replaceNamedRoute<sup>(deprecated)</sup>
941
942replaceNamedRoute(options: NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
943
944用指定的命名路由页面替换当前页面,并销毁被替换的页面。
945
946> **说明:**
947>
948> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceNamedRoute](arkts-apis-uicontext-router.md#replacenamedroute-1)。
949>
950> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
951
952**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
953
954**系统能力:** SystemCapability.ArkUI.ArkUI.Full
955
956**参数:**
957
958| 参数名  | 类型                            | 必填 | 说明               |
959| ------- | ------------------------------- | ---- | ------------------ |
960| options | [NamedRouterOptions](#namedrouteroptions10) | 是   | 替换页面描述信息。 |
961| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
962
963**错误码:**
964
965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
966> **说明**:
967>
968> 该接口返回的以下错误码均为string类型。
969
970| 错误码ID   | 错误信息 |
971| --------- | ------- |
972| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
973| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
974| 100004    | Named route error. The named route does not exist. |
975
976**示例:**
977
978```ts
979class RouterParams {
980  data1: string;
981
982  constructor(str: string) {
983    this.data1 = str;
984  }
985}
986
987router.replaceNamedRoute({
988  name: 'myPage',
989  params: new RouterParams('message')
990}, (err) => {
991  if (err) {
992    console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`);
993    return;
994  }
995  console.info('replaceNamedRoute success');
996})
997```
998
999## router.replaceNamedRoute<sup>(deprecated)</sup>
1000
1001replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode): Promise&lt;void&gt;
1002
1003用指定的命名路由页面替换当前页面,并销毁被替换的页面。
1004
1005> **说明:**
1006>
1007> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceNamedRoute](arkts-apis-uicontext-router.md#replacenamedroute-2)。
1008>
1009> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1010
1011**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1012
1013**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1014
1015**参数:**
1016
1017| 参数名     | 类型                              | 必填   | 说明         |
1018| ------- | ------------------------------- | ---- | ---------- |
1019| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 替换页面描述信息。  |
1020| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
1021
1022
1023**返回值:**
1024
1025| 类型                | 说明        |
1026| ------------------- | --------- |
1027| Promise&lt;void&gt; | 异常返回结果。 |
1028
1029**错误码:**
1030
1031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
1032> **说明**:
1033>
1034> 该接口返回的以下错误码均为string类型。
1035
1036| 错误码ID   | 错误信息 |
1037| --------- | ------- |
1038| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
1039| 100001    | Failed to get the delegate. This error code is thrown only in the standard system. |
1040| 100004    | Named route error. The named route does not exist. |
1041
1042**示例:**
1043
1044```ts
1045import { BusinessError } from '@kit.BasicServicesKit';
1046
1047class RouterParams {
1048  data1: string;
1049
1050  constructor(str: string) {
1051    this.data1 = str;
1052  }
1053}
1054
1055router.replaceNamedRoute({
1056  name: 'myPage',
1057  params: new RouterParams('message')
1058}, router.RouterMode.Standard)
1059  .then(() => {
1060    console.error(`replaceNamedRoute finish`);
1061  })
1062  .catch((err: ESObject) => {
1063    console.error(`replaceNamedRoute failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
1064  })
1065```
1066
1067## router.replaceNamedRoute<sup>(deprecated)</sup>
1068
1069replaceNamedRoute(options: NamedRouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
1070
1071用指定的命名路由页面替换当前页面,并销毁被替换的页面。
1072
1073> **说明:**
1074>
1075> 从API version 10开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[replaceNamedRoute](arkts-apis-uicontext-router.md#replacenamedroute-3)。
1076>
1077> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1078
1079**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1080
1081**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1082
1083**参数:**
1084
1085| 参数名     | 类型                              | 必填   | 说明         |
1086| ------- | ------------------------------- | ---- | ---------- |
1087| options | [NamedRouterOptions](#namedrouteroptions10) | 是    | 替换页面描述信息。  |
1088| mode    | [RouterMode](#routermode9)      | 是    | 跳转页面使用的模式。 |
1089| callback | AsyncCallback&lt;void&gt;      | 是   | 异常响应回调。   |
1090
1091**错误码:**
1092
1093以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
1094> **说明**:
1095>
1096> 该接口返回的以下错误码均为string类型。
1097
1098| 错误码ID   | 错误信息 |
1099| --------- | ------- |
1100| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
1101| 100001    | The UI execution context is not found. This error code is thrown only in the standard system. |
1102| 100004    | Named route error. The named route does not exist. |
1103
1104**示例:**
1105
1106```ts
1107class RouterParams {
1108  data1: string;
1109
1110  constructor(str: string) {
1111    this.data1 = str;
1112  }
1113}
1114
1115router.replaceNamedRoute({
1116  name: 'myPage',
1117  params: new RouterParams('message')
1118}, router.RouterMode.Standard, (err) => {
1119  if (err) {
1120    console.error(`replaceNamedRoute failed, code is ${err.code}, message is ${err.message}`);
1121    return;
1122  }
1123  console.info('replaceNamedRoute success');
1124});
1125```
1126
1127## router.back<sup>(deprecated)</sup>
1128
1129back(options?: RouterOptions ): void
1130
1131返回上一页面或指定的页面,会删除当前页面与指定页面之间的所有页面。
1132
1133> **说明:**
1134>
1135> 从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[back](arkts-apis-uicontext-router.md#back)。
1136>
1137> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1138
1139**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1140
1141**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1142
1143**参数:**
1144
1145| 参数名  | 类型                            | 必填 | 说明                                                         |
1146| ------- | ------------------------------- | ---- | ------------------------------------------------------------ |
1147| options | [RouterOptions](#routeroptions) | 否   | 返回页面描述信息,其中参数url指路由跳转时会返回到指定url的界面,如果页面栈上没有url页面,则不响应该情况。如果url未设置,则返回上一页,页面不会重新构建,页面栈里面的page不会回收,出栈后会被回收。back是返回接口,url设置为特殊值"/"不生效。如果是用命名路由的方式跳转,传入的url需是命名路由的名称。 |
1148
1149**示例:**
1150
1151```ts
1152this.getUIContext().getRouter().back({ url: 'pages/detail' });
1153```
1154
1155## router.back<sup>(deprecated)</sup>
1156
1157back(index: number, params?: Object): void;
1158
1159返回指定的页面,会删除当前页面与指定页面之间的所有页面。
1160
1161> **说明:**
1162>
1163> 从API version 12开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[back](arkts-apis-uicontext-router.md#back12)。
1164>
1165> 从API version 12开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1166
1167**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1168
1169**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1170
1171**参数:**
1172
1173| 参数名     | 类型                              | 必填   | 说明         |
1174| ------- | ------------------------------- | ---- | ---------- |
1175| index | number | 是    | 跳转目标页面的索引值。 从栈底到栈顶,index从1开始递增。 |
1176| params    | Object      | 否    | 页面返回时携带的参数。 |
1177
1178**示例:**
1179
1180```ts
1181this.getUIContext().getRouter().back(1);
1182```
1183```ts
1184this.getUIContext().getRouter().back(1, { info: '来自Home页' }); //携带参数返回
1185```
1186
1187## router.clear<sup>(deprecated)</sup>
1188
1189clear(): void
1190
1191清空页面栈中的所有历史页面,仅保留当前页面作为栈顶页面。
1192
1193> **说明:**
1194>
1195> 从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[clear](arkts-apis-uicontext-router.md#clear)。
1196>
1197> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1198
1199**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1200
1201**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1202
1203**示例:**
1204
1205```ts
1206this.getUIContext().getRouter().clear();
1207```
1208
1209## router.getLength<sup>(deprecated)</sup>
1210
1211getLength(): string
1212
1213获取当前在页面栈内的页面数量。
1214
1215> **说明:**
1216>
1217> 从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[getLength](arkts-apis-uicontext-router.md#getlength)。
1218>
1219> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1220
1221**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1222
1223**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1224
1225**返回值:**
1226
1227| 类型     | 说明                 |
1228| ------ | ------------------ |
1229| string | 页面数量,页面栈支持最大数值是32。 |
1230
1231**示例:**
1232
1233```ts
1234let size = this.getUIContext().getRouter().getLength();
1235console.info('pages stack size = ' + size);
1236```
1237
1238## router.getState<sup>(deprecated)</sup>
1239
1240getState(): RouterState
1241
1242获取栈顶页面的状态信息。
1243
1244> **说明:**
1245>
1246> 从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[getState](arkts-apis-uicontext-router.md#getstate)。
1247>
1248> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1249
1250**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1251
1252**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1253
1254**返回值:**
1255
1256| 类型                          | 说明      |
1257| --------------------------- | ------- |
1258| [RouterState](#routerstate) | 页面状态信息。 |
1259
1260**示例:**
1261
1262```ts
1263let page = this.getUIContext().getRouter().getState();
1264console.info('current index = ' + page.index);
1265console.info('current name = ' + page.name);
1266console.info('current path = ' + page.path);
1267```
1268
1269## router.getStateByIndex<sup>(deprecated)</sup>
1270
1271getStateByIndex(index: number): RouterState | undefined
1272
1273通过索引值获取对应页面的状态信息。
1274
1275> **说明:**
1276>
1277> 从API version 12开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[getStateByIndex](arkts-apis-uicontext-router.md#getstatebyindex12)。
1278>
1279> 从API version 12开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1280
1281**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1282
1283**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1284
1285**参数:**
1286
1287| 参数名     | 类型                              | 必填   | 说明         |
1288| ------- | ------------------------------- | ---- | ---------- |
1289| index    | number | 是   | 表示要获取的页面索引。从栈底到栈顶,index从1开始递增。 |
1290
1291**返回值:**
1292
1293| 类型                          | 说明      |
1294| --------------------------- | ------- |
1295| [RouterState](#routerstate) \| undefined | 返回页面状态信息。索引不存在时返回undefined。 |
1296
1297**示例:**
1298
1299```ts
1300let options: router.RouterState | undefined = router.getStateByIndex(1);
1301if (options != undefined) {
1302  console.info('index = ' + options.index);
1303  console.info('name = ' + options.name);
1304  console.info('path = ' + options.path);
1305  console.info(`params = ${JSON.stringify(options.params)}`);
1306}
1307```
1308## router.getStateByUrl<sup>(deprecated)</sup>
1309
1310getStateByUrl(url: string): Array&lt;RouterState&gt;
1311
1312通过url获取对应页面的状态信息。
1313
1314> **说明:**
1315>
1316> 从API version 12开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[getStateByUrl](arkts-apis-uicontext-router.md#getstatebyurl12)。
1317>
1318> 从API version 12开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1319
1320**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1321
1322**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1323
1324**参数:**
1325
1326| 参数名     | 类型                              | 必填   | 说明         |
1327| ------- | ------------------------------- | ---- | ---------- |
1328| url    | string | 是   | 表示要获取对应页面信息的url。  |
1329
1330**返回值:**
1331
1332| 类型                          | 说明      |
1333| --------------------------- | ------- |
1334| Array<[RouterState](#routerstate)> | 页面状态信息。 |
1335
1336**示例:**
1337
1338```ts
1339let options: Array<router.RouterState> = router.getStateByUrl('pages/index');
1340for (let i: number = 0; i < options.length; i++) {
1341  console.info('index = ' + options[i].index);
1342  console.info('name = ' + options[i].name);
1343  console.info('path = ' + options[i].path);
1344  console.info('params = ' + options[i].params);
1345}
1346```
1347
1348## RouterState
1349
1350页面状态信息。
1351
1352**系统能力:** SystemCapability.ArkUI.ArkUI.Full1353
1354| 名称  | 类型   | 必填 | 说明                                                         |
1355| ----- | ------ | ---- | ------------------------------------------------------------ |
1356| index | number | 是   | 表示当前页面在页面栈中的索引。从栈底到栈顶,index从1开始递增。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1357| name  | string | 是  | 表示当前页面的名称,即对应文件名。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1358| path  | string | 是   | 表示当前页面的路径。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1359| params<sup>12+</sup>  | Object |  是  | 表示当前页面携带的参数。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                         |
1360
1361## router.showAlertBeforeBackPage<sup>(deprecated)</sup>
1362
1363showAlertBeforeBackPage(options: EnableAlertOptions): void
1364
1365开启页面返回询问对话框。
1366
1367> **说明:**
1368>
1369> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[showAlertBeforeBackPage](arkts-apis-uicontext-router.md#showalertbeforebackpage)。
1370>
1371> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1372
1373**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1374
1375**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1376
1377**参数:**
1378
1379| 参数名     | 类型                                       | 必填   | 说明        |
1380| ------- | ---------------------------------------- | ---- | --------- |
1381| options | [EnableAlertOptions](#enablealertoptions) | 是    | 文本弹窗信息描述。 |
1382
1383**错误码:**
1384
1385以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.router(页面路由)](errorcode-router.md)错误码。
1386
1387| 错误码ID   | 错误信息 |
1388| --------- | ------- |
1389| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
1390| 100001    | Internal error. |
1391
1392**示例:**
1393
1394```ts
1395import { BusinessError } from '@kit.BasicServicesKit';
1396
1397try {
1398  this.getUIContext().getRouter().showAlertBeforeBackPage({
1399    message: 'Message Info'
1400  });
1401} catch (err) {
1402  console.error(`showAlertBeforeBackPage failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
1403}
1404```
1405## EnableAlertOptions
1406
1407页面返回询问对话框选项。
1408
1409**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1410
1411**系统能力:** 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full1412
1413| 名称      | 类型     | 必填   | 说明       |
1414| ------- | ------ | ---- | -------- |
1415| message | string | 是    | 询问对话框内容。 |
1416
1417## router.hideAlertBeforeBackPage<sup>(deprecated)</sup>
1418
1419hideAlertBeforeBackPage(): void
1420
1421禁用页面返回询问对话框。
1422
1423> **说明:**
1424>
1425> 从API version 9开始支持,从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[hideAlertBeforeBackPage](arkts-apis-uicontext-router.md#hidealertbeforebackpage)。
1426>
1427> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1428
1429**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1430
1431**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1432
1433**示例:**
1434
1435```ts
1436this.getUIContext().getRouter().hideAlertBeforeBackPage();
1437```
1438
1439##  router.getParams<sup>(deprecated)</sup>
1440
1441getParams(): Object
1442
1443获取发起跳转的页面往当前页传入的参数。
1444
1445> **说明:**
1446>
1447> 从API version 18开始废弃,建议使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取[Router](arkts-apis-uicontext-router.md)实例,再通过此实例调用替代方法[getParams](arkts-apis-uicontext-router.md#getparams)。
1448>
1449> 从API version 10开始,可以通过使用[UIContext](arkts-apis-uicontext-uicontext.md)中的[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)方法获取当前UI上下文关联的[Router](arkts-apis-uicontext-router.md)对象。
1450>
1451> getParams只获取当前页面的参数,并不会清除页面关联的参数。
1452
1453**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1454
1455**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1456
1457**返回值:**
1458
1459| 类型   | 说明                               |
1460| ------ | ---------------------------------- |
1461| Object | 发起跳转的页面往当前页传入的参数。 |
1462
1463**示例:**
1464
1465```ts
1466this.getUIContext().getRouter().getParams();
1467```
1468
1469## RouterOptions
1470
1471路由跳转选项。
1472
1473**系统能力:** SystemCapability.ArkUI.ArkUI.Lite1474
1475| 名称   | 类型   | 必填 | 说明                                                         |
1476| ------ | ------ | ---- | ------------------------------------------------------------ |
1477| url    | string | 是   | 表示目标页面的url,可以用以下两种格式:<br/>-&nbsp;页面绝对路径,由配置文件中pages列表提供,例如:<br/>&nbsp;&nbsp;-&nbsp;pages/index/index<br/>&nbsp;&nbsp;-&nbsp;pages/detail/detail<br/>-&nbsp;特殊值,如果url的值是"/",则跳转到首页,首页默认为页面跳转配置项src数组的第一个数据项。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1478| params | Object | 否   | 表示路由跳转时要同时传递到目标页面的数据,切换到其他页面时,当前接收的数据失效。跳转到目标页面后,使用router.getParams()获取传递的参数,此外,在类web范式中,参数也可以在页面中直接使用,如this.keyValue(keyValue为跳转时params参数中的key值),如果目标页面中已有该字段,则其值会被传入的字段值覆盖。<br/>**说明:** <br/>params参数只能传递可序列化的参数,不能传递方法和系统接口返回的对象(例如,媒体接口定义和返回的PixelMap对象)。建议开发者提取系统接口返回的对象中需要被传递的基础类型属性,自行构造object类型对象进行传递。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1479| recoverable<sup>14+</sup> | boolean | 否   | 表示对应的页面是否可恢复,默认为true。当为true时,表示可恢复,当为false时,表示不可恢复。<br/>**说明:** <br/> 当应用退到后台,并且在未来的某个时间点,由于系统资源限制等原因被系统杀死,如果某个页面被设置成可恢复,那么该应用再次被拉到前台后系统可以恢复出页面,详细说明请参考[UIAbility备份恢复](../../application-models/ability-recover-guideline.md)。 |
1480
1481  > **说明:**
1482  > 页面路由栈支持的最大Page数量为32。
1483
1484## RouterMode<sup>9+</sup>
1485
1486路由跳转模式。
1487
1488**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1489
1490**系统能力:** SystemCapability.ArkUI.ArkUI.Full1491
1492| 名称     | 值 | 说明                                                         |
1493| -------- | --- | ------------------------------------------------------------ |
1494| Standard | 0 | 多实例模式,也是默认情况下的跳转模式。 <br/>目标页面会被添加到页面栈顶,无论栈中是否存在相同url的页面。<br/>**说明:**  <br/>不使用路由跳转模式时,则按照默认的多实例模式进行跳转。 |
1495| Single   | 1 | 单实例模式。<br/>如果目标页面的url已经存在于页面栈中,则该url页面移动到栈顶。<br />如果目标页面的url在页面栈中不存在同url页面,则按照默认的多实例模式进行跳转。 |
1496
1497## NamedRouterOptions<sup>10+</sup>
1498
1499命名路由跳转选项。
1500
1501| 名称   | 类型   | 必填 | 说明                                                         |
1502| ------ | ------ | ---- | ------------------------------------------------------------ |
1503| name   | string | 是   | 表示目标命名路由页面的name。 <br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 <br/>**系统能力:** SystemCapability.ArkUI.ArkUI.Full |
1504| params | Object | 否   | 表示路由跳转时要同时传递到目标页面的数据。跳转到目标页面后,使用router.getParams()获取传递的参数,此外,在类web范式中,参数也可以在页面中直接使用,如this.keyValue(keyValue为跳转时params参数中的key值),如果目标页面中已有该字段,则其值会被传入的字段值覆盖。 <br/>**说明:** <br/>params参数不能传递方法和系统接口返回的对象(例如,媒体接口定义和返回的PixelMap对象)。建议开发者提取系统接口返回的对象中需要被传递的基础类型属性,自行构造object类型对象进行传递。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。<br/>**系统能力:** SystemCapability.ArkUI.ArkUI.Full  |
1505| recoverable<sup>14+</sup> | boolean | 否   | 表示对应的页面是否可恢复,默认为true。当为true时,表示可恢复,当为false时,表示不可恢复。<br/>**说明:** <br/> 当应用退到后台,并且在未来的某个时间点,由于系统资源限制等原因被系统杀死,如果某个页面被设置成可恢复,那么该应用再次被拉到前台后系统可以恢复出页面,详细说明请参考[UIAbility备份恢复](../../application-models/ability-recover-guideline.md)。 <br/>**系统能力:** SystemCapability.ArkUI.ArkUI.Lite |
1506
1507## 完整示例
1508
1509### 基于JS扩展的类Web开发范式
1510
1511以下代码仅适用于javascript文件,不适用于ArkTS文件
1512
1513<!--code_no_check-->
1514
1515```js
1516// 在当前页面中
1517export default {
1518  pushPage() {
1519    router.pushUrl({
1520      url: 'pages/detail/detail',
1521      params: {
1522        data1: 'message'
1523      }
1524    });
1525  }
1526}
1527```
1528<!--code_no_check-->
1529
1530```js
1531// 在detail页面中
1532export default {
1533  onInit() {
1534    console.info('showData1:' + this.getUIContext().getRouter().getParams()['data1']);
1535  }
1536}
1537```
1538
1539### 基于TS扩展的声明式开发范式
1540
1541> **说明:**
1542>
1543> 直接使用router可能导致[UI上下文不明确](../../ui/arkts-global-interface.md#ui上下文不明确)的问题,建议使用getUIContext获取[UIContext](arkts-apis-uicontext-uicontext.md)实例,并使用[getRouter](arkts-apis-uicontext-uicontext.md#getrouter)获取绑定实例的router。
1544
1545<!--deperecated_code_no_check-->
1546```ts
1547// 通过router.pushUrl跳转至目标页携带params参数
1548import { router } from '@kit.ArkUI';
1549import { BusinessError } from '@kit.BasicServicesKit';
1550
1551// 定义传递参数的类
1552class innerParams {
1553  array: number[];
1554
1555  constructor(tuple: number[]) {
1556    this.array = tuple;
1557  }
1558}
1559
1560class RouterParams {
1561  text: string;
1562  data: innerParams;
1563
1564  constructor(str: string, tuple: number[]) {
1565    this.text = str;
1566    this.data = new innerParams(tuple);
1567  }
1568}
1569
1570@Entry
1571@Component
1572struct Index {
1573  async routePage() {
1574    let options: router.RouterOptions = {
1575      url: 'pages/second',
1576      params: new RouterParams('这是第一页的值', [12, 45, 78])
1577    }
1578    // 建议使用this.getUIContext().getRouter().pushUrl()
1579    this.getUIContext().getRouter().pushUrl(options)
1580      .then(() => {
1581        console.error(`pushUrl finish`);
1582      })
1583      .catch((err: ESObject) => {
1584        console.error(`pushUrl failed, code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`);
1585      })
1586    }
1587
1588  build() {
1589    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1590      Text('这是第一页')
1591        .fontSize(50)
1592        .fontWeight(FontWeight.Bold)
1593      Button() {
1594        Text('next page')
1595          .fontSize(25)
1596          .fontWeight(FontWeight.Bold)
1597      }.type(ButtonType.Capsule)
1598      .margin({ top: 20 })
1599      .backgroundColor('#ccc')
1600      .onClick(() => {
1601        this.routePage()
1602      })
1603    }
1604    .width('100%')
1605    .height('100%')
1606  }
1607}
1608```
1609
1610```ts
1611// 在second页面中接收传递过来的参数
1612import { router } from '@kit.ArkUI';
1613
1614class innerParams {
1615  array: number[];
1616
1617  constructor(tuple: number[]) {
1618    this.array = tuple;
1619  }
1620}
1621
1622class RouterParams {
1623  text: string;
1624  data: innerParams;
1625
1626  constructor(str: string, tuple: number[]) {
1627    this.text = str;
1628    this.data = new innerParams(tuple);
1629  }
1630}
1631
1632@Entry
1633@Component
1634struct Second {
1635  private content: string = "这是第二页";
1636  // 建议使用this.getUIContext().getRouter().getParams()
1637  @State text: string = (this.getUIContext().getRouter().getParams() as RouterParams).text;
1638  @State data: object = (this.getUIContext().getRouter().getParams() as RouterParams).data;
1639  @State secondData: string = '';
1640
1641  build() {
1642    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1643      Text(`${this.content}`)
1644        .fontSize(50)
1645        .fontWeight(FontWeight.Bold)
1646      Text(this.text)
1647        .fontSize(30)
1648        .onClick(() => {
1649          this.secondData = (this.data['array'][1]).toString();
1650        })
1651        .margin({ top: 20 })
1652      Text(`第一页传来的数值:${this.secondData}`)
1653        .fontSize(20)
1654        .margin({ top: 20 })
1655        .backgroundColor('red')
1656    }
1657    .width('100%')
1658    .height('100%')
1659  }
1660}
1661```
1662
1663## router.push<sup>(deprecated)</sup>
1664
1665push(options: RouterOptions): void
1666
1667跳转到应用内的指定页面。
1668
1669从API version9开始不再维护,建议使用[pushUrl](arkts-apis-uicontext-router.md#pushurl)
1670
1671**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1672
1673**参数:**
1674
1675| 参数名     | 类型                              | 必填   | 说明        |
1676| ------- | ------------------------------- | ---- | --------- |
1677| options | [RouterOptions](#routeroptions) | 是    | 跳转页面描述信息。 |
1678
1679
1680**示例:**
1681
1682```ts
1683class innerParams {
1684  data3: number[];
1685
1686  constructor(tuple: number[]) {
1687    this.data3 = tuple;
1688  }
1689}
1690
1691class RouterParams {
1692  data1: string;
1693  data2: innerParams;
1694
1695  constructor(str: string, tuple: number[]) {
1696    this.data1 = str;
1697    this.data2 = new innerParams(tuple);
1698  }
1699}
1700
1701router.push({
1702  url: 'pages/routerpage2',
1703  params: new RouterParams('message', [123, 456, 789])
1704});
1705```
1706
1707## router.replace<sup>(deprecated)</sup>
1708
1709replace(options: RouterOptions): void
1710
1711用应用内的某个页面替换当前页面,并销毁被替换的页面。
1712
1713从API version9开始不再维护,建议使用[replaceUrl](arkts-apis-uicontext-router.md#replaceurl)
1714
1715**系统能力:** SystemCapability.ArkUI.ArkUI.Lite
1716
1717**参数:**
1718
1719| 参数名  | 类型                            | 必填 | 说明               |
1720| ------- | ------------------------------- | ---- | ------------------ |
1721| options | [RouterOptions](#routeroptions) | 是   | 替换页面描述信息。 |
1722
1723**示例:**
1724
1725```ts
1726class RouterParams {
1727  data1: string;
1728
1729  constructor(str: string) {
1730    this.data1 = str;
1731  }
1732}
1733
1734router.replace({
1735  url: 'pages/detail',
1736  params: new RouterParams('message')
1737});
1738```
1739
1740## router.enableAlertBeforeBackPage<sup>(deprecated)</sup>
1741
1742enableAlertBeforeBackPage(options: EnableAlertOptions): void
1743
1744开启页面返回询问对话框。
1745
1746从API version9开始不再维护,建议使用[showAlertBeforeBackPage](arkts-apis-uicontext-router.md#showalertbeforebackpage)
1747
1748**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1749
1750**参数:**
1751
1752| 参数名     | 类型                                       | 必填   | 说明        |
1753| ------- | ---------------------------------------- | ---- | --------- |
1754| options | [EnableAlertOptions](#enablealertoptions) | 是    | 文本弹窗信息描述。 |
1755
1756**示例:**
1757
1758```ts
1759router.enableAlertBeforeBackPage({
1760  message: 'Message Info'
1761});
1762```
1763
1764## router.disableAlertBeforeBackPage<sup>(deprecated)</sup>
1765
1766disableAlertBeforeBackPage(): void
1767
1768禁用页面返回询问对话框。
1769
1770从API version9开始不再维护,建议使用[hideAlertBeforeBackPage](arkts-apis-uicontext-router.md#hidealertbeforebackpage)
1771
1772**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1773
1774**示例:**
1775
1776```ts
1777router.disableAlertBeforeBackPage();
1778```
1779