提交 2407af88 编写于 作者: G Gloria

Update docs against 10174+10828+10804+11009+10922

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 5abb47bf
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
- [@ohos.application.formInfo](js-apis-formInfo.md) - [@ohos.application.formInfo](js-apis-formInfo.md)
- [@ohos.application.formProvider](js-apis-formprovider.md) - [@ohos.application.formProvider](js-apis-formprovider.md)
- [@ohos.application.missionManager](js-apis-missionManager.md) - [@ohos.application.missionManager](js-apis-missionManager.md)
- [@ohos.application.quickFixManager](js-apis-application-quickFixManager.md)
- [@ohos.application.Want](js-apis-application-Want.md) - [@ohos.application.Want](js-apis-application-Want.md)
- [@ohos.continuation.continuationManager](js-apis-continuation-continuationExtraParams.md) - [@ohos.continuation.continuationManager](js-apis-continuation-continuationExtraParams.md)
- [@ohos.continuation.continuationManager](js-apis-continuation-continuationManager.md) - [@ohos.continuation.continuationManager](js-apis-continuation-continuationManager.md)
...@@ -90,8 +91,8 @@ ...@@ -90,8 +91,8 @@
- UI Page - UI Page
- [@ohos.animator](js-apis-animator.md) - [@ohos.animator](js-apis-animator.md)
- [@ohos.mediaquery](js-apis-mediaquery.md) - [@ohos.mediaquery](js-apis-mediaquery.md)
- [@ohos.promptAction](js-apis-promptAction.md)
- [@ohos.router](js-apis-router.md) - [@ohos.router](js-apis-router.md)
- [@ohos.uiAppearance](js-apis-uiappearance.md)
- Graphics - Graphics
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md) - [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.display ](js-apis-display.md) - [@ohos.display ](js-apis-display.md)
...@@ -146,6 +147,7 @@ ...@@ -146,6 +147,7 @@
- [@ohos.document](js-apis-document.md) - [@ohos.document](js-apis-document.md)
- [@ohos.environment](js-apis-environment.md) - [@ohos.environment](js-apis-environment.md)
- [@ohos.fileio](js-apis-fileio.md) - [@ohos.fileio](js-apis-fileio.md)
- [@ohos.filemanagement.userfile_manager](js-apis-userfilemanager.md)
- [@ohos.multimedia.medialibrary](js-apis-medialibrary.md) - [@ohos.multimedia.medialibrary](js-apis-medialibrary.md)
- [@ohos.securityLabel](js-apis-securityLabel.md) - [@ohos.securityLabel](js-apis-securityLabel.md)
- [@ohos.statfs](js-apis-statfs.md) - [@ohos.statfs](js-apis-statfs.md)
...@@ -261,6 +263,7 @@ ...@@ -261,6 +263,7 @@
- [@ohos.application.testRunner](js-apis-testRunner.md) - [@ohos.application.testRunner](js-apis-testRunner.md)
- [@ohos.uitest](js-apis-uitest.md) - [@ohos.uitest](js-apis-uitest.md)
- APIs No Longer Maintained - APIs No Longer Maintained
- [@ohos.bundleState](js-apis-deviceUsageStatistics.md)
- [@ohos.bytrace](js-apis-bytrace.md) - [@ohos.bytrace](js-apis-bytrace.md)
- [@ohos.data.storage](js-apis-data-storage.md) - [@ohos.data.storage](js-apis-data-storage.md)
- [@ohos.data.distributedData](js-apis-distributed-data.md) - [@ohos.data.distributedData](js-apis-distributed-data.md)
......
...@@ -4,6 +4,8 @@ The **Prompt** module provides APIs for creating and showing toasts, dialog boxe ...@@ -4,6 +4,8 @@ The **Prompt** module provides APIs for creating and showing toasts, dialog boxe
> **NOTE** > **NOTE**
> >
> The APIs of this module are deprecated since API Version 9. You are advised to use [@ohos.promptAction](js-apis-promptAction.md) instead.
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -35,6 +37,8 @@ prompt.showToast({ ...@@ -35,6 +37,8 @@ prompt.showToast({
}); });
``` ```
![en-us_image_0001](figures/en-us_image_0001.gif)
## ShowToastOptions ## ShowToastOptions
Describes the options for showing the toast. Describes the options for showing the toast.
...@@ -43,9 +47,9 @@ Describes the options for showing the toast. ...@@ -43,9 +47,9 @@ Describes the options for showing the toast.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| message | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Text to display. | | message | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | Yes | Text to display. |
| duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.| | duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.|
| bottom | string\| number | No | Distance between the toast border and the bottom of the screen. | | bottom | string\| number | No | Distance between the toast border and the bottom of the screen. It does not have an upper limit. The default unit is vp. |
## prompt.showDialog ## prompt.showDialog
...@@ -92,6 +96,8 @@ prompt.showDialog({ ...@@ -92,6 +96,8 @@ prompt.showDialog({
}) })
``` ```
![en-us_image_0002](figures/en-us_image_0002.gif)
## prompt.showDialog ## prompt.showDialog
showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
...@@ -132,6 +138,8 @@ prompt.showDialog({ ...@@ -132,6 +138,8 @@ prompt.showDialog({
}); });
``` ```
![en-us_image_0004](figures/en-us_image_0004.gif)
## ShowDialogOptions ## ShowDialogOptions
Describes the options for showing the dialog box. Describes the options for showing the dialog box.
...@@ -140,8 +148,8 @@ Describes the options for showing the dialog box. ...@@ -140,8 +148,8 @@ Describes the options for showing the dialog box.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Title of the dialog box. | | title | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | No | Title of the dialog box. |
| message | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Text body. | | message | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | No | Text body. |
| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.| | buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.|
## ShowDialogSuccessResponse ## ShowDialogSuccessResponse
...@@ -170,7 +178,6 @@ Shows an action menu. This API uses a callback to return the result asynchronous ...@@ -170,7 +178,6 @@ Shows an action menu. This API uses a callback to return the result asynchronous
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | | options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. |
| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.| | callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.|
**Example** **Example**
```js ```js
...@@ -195,6 +202,8 @@ prompt.showActionMenu({ ...@@ -195,6 +202,8 @@ prompt.showActionMenu({
}) })
``` ```
![en-us_image_0005](figures/en-us_image_0005.gif)
## prompt.showActionMenu ## prompt.showActionMenu
showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt; showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
...@@ -238,6 +247,8 @@ prompt.showActionMenu({ ...@@ -238,6 +247,8 @@ prompt.showActionMenu({
console.info('showActionMenu error: ' + err); console.info('showActionMenu error: ' + err);
}) })
``` ```
![en-us_image_0006](figures/en-us_image_0006.gif)
## ActionMenuOptions ## ActionMenuOptions
Describes the options for showing the action menu. Describes the options for showing the action menu.
...@@ -246,7 +257,7 @@ Describes the options for showing the action menu. ...@@ -246,7 +257,7 @@ Describes the options for showing the action menu.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Title of the text to display. | | title | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | No | Title of the text to display. |
| buttons | Array&lt;[Button](#button)&gt; | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| | buttons | Array&lt;[Button](#button)&gt; | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.|
## ActionMenuSuccessResponse ## ActionMenuSuccessResponse
...@@ -267,5 +278,5 @@ Describes the menu item button in the action menu. ...@@ -267,5 +278,5 @@ Describes the menu item button in the action menu.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ---------------------------------------- | ---- | ------- | | ----- | ---------------------------------------- | ---- | ------- |
| text | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Button text.| | text | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | Yes | Button text.|
| color | string\| [Resource](../../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Text color of the button.| | color | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup> | Yes | Text color of the button.|
# Prompt
The **PromptAction** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import promptAction from '@ohos.promptAction'
```
## promptAction.showToast
showToast(options: ShowToastOptions): void
Shows a toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------- | ---- | ------- |
| options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.|
**Error codes**
For details about the error codes, see [promptAction Error Codes](../errorcodes/errorcode-promptAction.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example**
```js
try {
promptAction.showToast({
message: 'Message Info',
duration: 2000,
});
} catch (error) {
console.error(`showToast args error code is ${error.code}, message is ${error.message}`);
};
```
![en-us_image_0001](figures/en-us_image_0001.gif)
## ShowToastOptions
Describes the options for showing the toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| message | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| Yes | Text to display. |
| duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.|
| bottom | string\| number | No | Distance between the toast border and the bottom of the screen. |
## promptAction.showDialog
showDialog(options: ShowDialogOptions): Promise&lt;ShowDialogSuccessResponse&gt;
Shows a dialog box. This API uses a promise to return the result synchronously.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | --------------------------------------- | ---- | ------ |
| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------- |
| Promise&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Promise used to return the dialog box response result.|
**Error codes**
For details about the error codes, see [promptAction Error Codes](../errorcodes/errorcode-promptAction.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example**
```js
try {
promptAction.showDialog({
title: 'Title Info',
message: 'Message Info',
buttons: [
{
text: 'button1',
color: '#000000',
},
{
text: 'button2',
color: '#000000',
}
],
})
.then(data => {
console.info('showDialog success, click button: ' + data.index);
})
.catch(err => {
console.info('showDialog error: ' + err);
})
} catch (error) {
console.error(`showDialog args error code is ${error.code}, message is ${error.message}`);
};
```
![en-us_image_0002](figures/en-us_image_0002.gif)
## promptAction.showDialog
showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
Shows a dialog box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------ |
| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.|
| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Yes | Callback used to return the dialog box response result. |
**Error codes**
For details about the error codes, see [promptAction Error Codes](../errorcodes/errorcode-promptAction.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example**
```js
try {
promptAction.showDialog({
title: 'showDialog Title Info',
message: 'Message Info',
buttons: [
{
text: 'button1',
color: '#000000',
},
{
text: 'button2',
color: '#000000',
}
]
}, (err, data) => {
if (err) {
console.info('showDialog err: ' + err);
return;
}
console.info('showDialog success callback, click button: ' + data.index);
});
} catch (error) {
console.error(`showDialog args error code is ${error.code}, message is ${error.message}`);
};
```
![en-us_image_0002](figures/en-us_image_0002.gif)
## ShowDialogOptions
Describes the options for showing the dialog box.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| No | Title of the dialog box. |
| message | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| No | Text body. |
| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.|
## ShowDialogSuccessResponse
Describes the dialog box response result.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Description |
| ----- | ------ | ------------------- |
| index | number | Index of the selected button in the **buttons** array.|
## promptAction.showActionMenu
showActionMenu(options: ActionMenuOptions, callback: AsyncCallback&lt;ActionMenuSuccessResponse&gt;):void
Shows an action menu. This API uses a callback to return the result asynchronously.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------- |
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. |
| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.|
**Error codes**
For details about the error codes, see [promptAction Error Codes](../errorcodes/errorcode-promptAction.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example**
```js
try {
promptAction.showActionMenu({
title: 'Title Info',
buttons: [
{
text: 'item1',
color: '#666666',
},
{
text: 'item2',
color: '#000000',
},
]
}, (err, data) => {
if (err) {
console.info('showActionMenu err: ' + err);
return;
}
console.info('showActionMenu success callback, click button: ' + data.index);
})
} catch (error) {
console.error(`showActionMenu args error code is ${error.code}, message is ${error.message}`);
};
```
![en-us_image_0005](figures/en-us_image_0005.gif)
## promptAction.showActionMenu
showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
Shows an action menu. This API uses a promise to return the result synchronously.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | --------------------------------------- | ---- | ------- |
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------- |
| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.|
**Error codes**
For details about the error codes, see [promptAction Error Codes](../errorcodes/errorcode-promptAction.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example**
```js
try {
promptAction.showActionMenu({
title: 'showActionMenu Title Info',
buttons: [
{
text: 'item1',
color: '#666666',
},
{
text: 'item2',
color: '#000000',
},
]
})
.then(data => {
console.info('showActionMenu success, click button: ' + data.index);
})
.catch(err => {
console.info('showActionMenu error: ' + err);
})
} catch (error) {
console.error(`showActionMenu args error code is ${error.code}, message is ${error.message}`);
};
```
![en-us_image_0005](figures/en-us_image_0005.gif)
## ActionMenuOptions
Describes the options for showing the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| No | Title of the dialog box. |
| buttons | Array&lt;[Button](#button)&gt; | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.|
## ActionMenuSuccessResponse
Describes the action menu response result.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ------------------------ |
| index | number | No | Index of the selected button in the **buttons** array, starting from **0**.|
## Button
Describes the menu item button in the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ----- | ---------------------------------------- | ---- | ------- |
| text | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| Yes | Button text.|
| color | string\| [Resource](../arkui-ts/ts-types.md#resource)<sup>9+</sup>| Yes | Text color of the button.|
...@@ -14,108 +14,404 @@ The **Router** module provides APIs to access pages through URLs. You can use th ...@@ -14,108 +14,404 @@ The **Router** module provides APIs to access pages through URLs. You can use th
import router from '@ohos.router' import router from '@ohos.router'
``` ```
## router.push ## router.pushUrl<sup>9+</sup>
push(options: RouterOptions): void pushUrl(options: RouterOptions): Promise&lt;void&gt;
Navigates to a specified page in the application. Navigates to a specified page in the application.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | --------- | | ------- | ------------------------------- | ---- | --------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters.| | options | [RouterOptions](#routeroptions) | Yes | Page routing parameters.|
**Return value**
| Type | Description |
| ------------------- | --------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 100002 | Uri error. The uri of router is not exist. |
| 100003 | Page stack error. The pages are pushed too much. |
**Example** **Example**
```js ```js
router.push({ try {
url: 'pages/routerpage2', router.pushUrl({
params: { url: 'pages/routerpage2',
data1: 'message', params: {
data2: { data1: 'message',
data3: [123, 456, 789] data2: {
data3: [123, 456, 789]
},
}, },
}, })
}); .then(() => {
// success
})
.catch(err => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
console.error(`pushUrl args error code is ${error.code}, message is ${error.message}`);
};
``` ```
## router.push<sup>9+</sup>
push(options: RouterOptions, mode: RouterMode): void ## router.pushUrl<sup>9+</sup>
pushUrl(options: RouterOptions, callback: AsyncCallback&lt;void&gt;): void
Navigates to a specified page in the application.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | --------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 100002 | Uri error. The uri of router is not exist. |
| 100003 | Page stack error. The pages are pushed too much. |
**Example**
```js
try {
router.pushUrl({
url: 'pages/routerpage2',
params: {
data1: 'message',
data2: {
data3: [123, 456, 789]
},
},
}, (err) => {
if (err) {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
return;
}
console.info('pushUrl success');
});
} catch (error) {
console.error(`pushUrl args error code is ${error.code}, message is ${error.message}`);
};
```
## router.pushUrl<sup>9+</sup>
pushUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt;
Navigates to a specified page in the application. Navigates to a specified page in the application.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- | | ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. | | options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.| | mode | [RouterMode](#routermode9) | Yes | Routing mode.|
**Return value**
| Type | Description |
| ------------------- | --------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 100002 | Uri error. The uri of router is not exist. |
| 100003 | Page stack error. The pages are pushed too much. |
**Example** **Example**
```js ```js
router.push({ try {
url: 'pages/routerpage2/routerpage2', router.pushUrl({
params: { url: 'pages/routerpage2',
data1: 'message', params: {
data2: { data1: 'message',
data3: [123, 456, 789] data2: {
data3: [123, 456, 789]
},
}, },
}, }, router.RouterMode.Standard)
},router.RouterMode.Standard); .then(() => {
// success
})
.catch(err => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
console.error(`pushUrl args error code is ${error.code}, message is ${error.message}`);
};
``` ```
## router.replace ## router.pushUrl<sup>9+</sup>
replace(options: RouterOptions): void pushUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
Replaces the current page with another one in the application and destroys the current page. Navigates to a specified page in the application.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 100002 | Uri error. The uri of router is not exist. |
| 100003 | Page stack error. The pages are pushed too much. |
**Example**
```js
try {
router.pushUrl({
url: 'pages/routerpage2',
params: {
data1: 'message',
data2: {
data3: [123, 456, 789]
},
},
}, router.RouterMode.Standard, (err) => {
if (err) {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
return;
}
console.info('pushUrl success');
});
} catch (error) {
console.error(`pushUrl args error code is ${error.code}, message is ${error.message}`);
};
```
## router.replaceUrl<sup>9+</sup>
replaceUrl(options: RouterOptions): Promise&lt;void&gt;
Replaces the current page with another one in the application and destroys the current page.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ------------------ | | ------- | ------------------------------- | ---- | ------------------ |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page.| | options | [RouterOptions](#routeroptions) | Yes | Description of the new page.|
**Return value**
| Type | Description |
| ------------------- | --------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
**Example** **Example**
```js ```js
router.replace({ try {
url: 'pages/detail', router.replaceUrl({
params: { url: 'pages/detail',
data1: 'message', params: {
}, data1: 'message',
}); },
})
.then(() => {
// success
})
.catch(err => {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
console.error(`replaceUrl args error code is ${error.code}, message is ${error.message}`);
};
``` ```
## router.replace<sup>9+</sup> ## router.replaceUrl<sup>9+</sup>
replace(options: RouterOptions, mode: RouterMode): void replaceUrl(options: RouterOptions, callback: AsyncCallback&lt;void&gt;): void
Replaces the current page with another one in the application and destroys the current page. Replaces the current page with another one in the application and destroys the current page.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ------------------ |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
**Example**
```js
try {
router.replaceUrl({
url: 'pages/detail',
params: {
data1: 'message',
},
}, (err) => {
if (err) {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
return;
}
console.info('replaceUrl success');
});
} catch (error) {
console.error(`replaceUrl args error code is ${error.code}, message is ${error.message}`);
};
```
## router.replaceUrl<sup>9+</sup>
replaceUrl(options: RouterOptions, mode: RouterMode): Promise&lt;void&gt;
Replaces the current page with another one in the application and destroys the current page.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- | | ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. | | options | [RouterOptions](#routeroptions) | Yes | Description of the new page. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.| | mode | [RouterMode](#routermode9) | Yes | Routing mode.|
**Return value**
| Type | Description |
| ------------------- | --------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
**Example** **Example**
```js ```js
router.replace({ try {
url: 'pages/detail/detail', router.replaceUrl({
params: { url: 'pages/detail',
data1: 'message', params: {
}, data1: 'message',
}, router.RouterMode.Standard); },
}, router.RouterMode.Standard)
.then(() => {
// success
})
.catch(err => {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
console.error(`replaceUrl args error code is ${error.code}, message is ${error.message}`);
};
```
## router.replaceUrl<sup>9+</sup>
replaceUrl(options: RouterOptions, mode: RouterMode, callback: AsyncCallback&lt;void&gt;): void
Replaces the current page with another one in the application and destroys the current page.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
**Example**
```js
try {
router.replaceUrl({
url: 'pages/detail',
params: {
data1: 'message',
},
}, router.RouterMode.Standard, (err) => {
if (err) {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
return;
}
console.info('replaceUrl success');
});
} catch (error) {
console.error(`replaceUrl args error code is ${error.code}, message is ${error.message}`);
};
``` ```
## router.back ## router.back
...@@ -127,6 +423,7 @@ Returns to the previous page or a specified page. ...@@ -127,6 +423,7 @@ Returns to the previous page or a specified page.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| options | [RouterOptions](#routeroptions) | No | Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the previous page is returned, and the page in the page stack is not reclaimed. It will be reclaimed after being popped up.| | options | [RouterOptions](#routeroptions) | No | Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the previous page is returned, and the page in the page stack is not reclaimed. It will be reclaimed after being popped up.|
...@@ -160,11 +457,13 @@ Obtains the number of pages in the current stack. ...@@ -160,11 +457,13 @@ Obtains the number of pages in the current stack.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ------------------ | | ------ | ------------------ |
| string | Number of pages in the stack. The maximum value is **32**.| | string | Number of pages in the stack. The maximum value is **32**.|
**Example** **Example**
```js ```js
var size = router.getLength(); var size = router.getLength();
console.log('pages stack size = ' + size); console.log('pages stack size = ' + size);
...@@ -205,25 +504,38 @@ Describes the page routing state. ...@@ -205,25 +504,38 @@ Describes the page routing state.
| name | string | Name of the current page, that is, the file name. | | name | string | Name of the current page, that is, the file name. |
| path | string | Path of the current page. | | path | string | Path of the current page. |
## router.enableAlertBeforeBackPage ## router.enableBackPageAlert<sup>9+</sup>
enableAlertBeforeBackPage(options: EnableAlertOptions): void enableBackPageAlert(options: EnableAlertOptions): void
Enables the display of a confirm dialog box before returning to the previous page. Enables the display of a confirm dialog box before returning to the previous page.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | --------- | | ------- | ---------------------------------------- | ---- | --------- |
| options | [EnableAlertOptions](#enablealertoptions) | Yes | Description of the dialog box.| | options | [EnableAlertOptions](#enablealertoptions) | Yes | Description of the dialog box.|
**Error codes**
For details about the error codes, see [Router Error Codes](../errorcodes/errorcode-router.md).
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
**Example** **Example**
```js ```js
router.enableAlertBeforeBackPage({ try {
router.enableBackPageAlert({
message: 'Message Info' message: 'Message Info'
}); });
} catch(error) {
console.error(`enableBackPageAlert failed, code is ${error.code}, message is ${error.message}`);
}
``` ```
## EnableAlertOptions ## EnableAlertOptions
...@@ -244,6 +556,7 @@ Disables the display of a confirm dialog box before returning to the previous pa ...@@ -244,6 +556,7 @@ Disables the display of a confirm dialog box before returning to the previous pa
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
**Example** **Example**
```js ```js
router.disableAlertBeforeBackPage(); router.disableAlertBeforeBackPage();
``` ```
...@@ -274,10 +587,10 @@ Describes the page routing options. ...@@ -274,10 +587,10 @@ Describes the page routing options.
**System capability**: SystemCapability.ArkUI.ArkUI.Lite **System capability**: SystemCapability.ArkUI.ArkUI.Lite
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| url | string | Yes | URI of the destination page, in either of the following formats:<br>- Absolute path of the page. The value is available in the pages list in the **config.json** file, for example:<br>- pages/index/index<br>- pages/detail/detail<br>- Particular path. If the URI is a slash (/), the home page is displayed.| | url | string | Yes | URL of the target page, in either of the following formats:<br>- Absolute path of the page. The value is available in the pages list in the **config.json** file, for example:<br>- pages/index/index<br>- pages/detail/detail<br>- Particular path. If the URL is a slash (/), the home page is displayed.|
| params | Object | No | Data that needs to be passed to the destination page during redirection. After the destination page is displayed, it can use the passed data, for example, **this.data1** (**data1** is a key in **params**). If there is the same key (for example, **data1**) on the destination page, the passed **data1** value will replace the original value on the destination page.| | params | Object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.|
> **NOTE** > **NOTE**
...@@ -291,7 +604,7 @@ Enumerates the routing modes. ...@@ -291,7 +604,7 @@ Enumerates the routing modes.
| Name | Description | | Name | Description |
| -------- | ---------------------------------------- | | -------- | ---------------------------------------- |
| Standard | Standard mode. | | Standard | Standard mode.<br>The target page is added to the top of the page stack, regardless of whether a page with the same URL exists in the stack. |
| Single | Singleton mode.<br>If the URL of the target page already exists in the page stack, the page closest to the top of the stack is moved as a new page to the top of the stack.<br>If the URL of the target page does not exist in the page stack, the page is redirected to in standard mode.| | Single | Singleton mode.<br>If the URL of the target page already exists in the page stack, the page closest to the top of the stack is moved as a new page to the top of the stack.<br>If the URL of the target page does not exist in the page stack, the page is redirected to in standard mode.|
## Examples ## Examples
...@@ -401,3 +714,144 @@ struct Second { ...@@ -401,3 +714,144 @@ struct Second {
} }
} }
``` ```
## router.push<sup>(deprecated)</sup>
push(options: RouterOptions): void
Navigates to a specified page in the application.
This API is deprecated since API version 9. You are advised to use [pushUrl<sup>9+</sup>](#routerpushurl9) instead.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | --------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters.|
**Example**
```js
router.push({
url: 'pages/routerpage2',
params: {
data1: 'message',
data2: {
data3: [123, 456, 789]
},
},
});
```
## router.push<sup>(deprecated)</sup>
push(options: RouterOptions, mode: RouterMode): void
Navigates to a specified page in the application.
This API is deprecated since API version 9. You are advised to use [pushUrl<sup>9+</sup>](#routerpushurl9) instead.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Page routing parameters. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.|
**Example**
```js
router.push({
url: 'pages/routerpage2/routerpage2',
params: {
data1: 'message',
data2: {
data3: [123, 456, 789]
},
},
},router.RouterMode.Standard);
```
## router.replace<sup>(deprecated)</sup>
replace(options: RouterOptions): void
Replaces the current page with another one in the application and destroys the current page.
This API is deprecated since API version 9. You are advised to use [replaceUrl<sup>9+</sup>](#routerreplaceurl9) instead.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------- | ---- | ------------------ |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page.|
**Example**
```js
router.replace({
url: 'pages/detail',
params: {
data1: 'message',
},
});
```
## router.replace<sup>(deprecated)</sup>
replace(options: RouterOptions, mode: RouterMode): void
Replaces the current page with another one in the application and destroys the current page.
This API is deprecated since API version 9. You are advised to use [replaceUrl<sup>9+</sup>](#routerreplaceurl9) instead.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------- |
| options | [RouterOptions](#routeroptions) | Yes | Description of the new page. |
| mode | [RouterMode](#routermode9) | Yes | Routing mode.|
**Example**
```js
router.replace({
url: 'pages/detail/detail',
params: {
data1: 'message',
},
}, router.RouterMode.Standard);
```
## router.enableAlertBeforeBackPage<sup>(deprecated)</sup>
enableAlertBeforeBackPage(options: EnableAlertOptions): void
Enables the display of a confirm dialog box before returning to the previous page.
This API is deprecated since API version 9. You are advised to use [enableBackPageAlert<sup>9+</sup>](#routerenablebackpagealert9) instead.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | --------- |
| options | [EnableAlertOptions](#enablealertoptions) | Yes | Description of the dialog box.|
**Example**
```js
router.enableAlertBeforeBackPage({
message: 'Message Info'
});
```
# promptAction Error Codes
## 100001 Internal Error
**Error Message**
Internal error.
**Description**
This error code is reported when an internal error that cannot be rectified by developers occurs. The internal error type is included in the error information.
**Possible Causes**
The operation for obtaining the rendering engine or parsing parameters fails.
**Procedure**
NA
# Router Error Codes
## 100001 Internal Error
**Error Message**
Internal error.
**Description**
This error code is reported when an internal error that cannot be rectified by developers occurs. The internal error type is included in the error information.
**Possible Causes**
The operation for obtaining the rendering engine or parsing parameters fails.
**Procedure**
NA
## 100002 Incorrect URI
**Error Message**
Uri error. The uri of router is not exist.
**Description**
This error code is reported when the URI of the page to redirect is incorrect or does not exist.
**Possible Causes**
The entered URI is incorrect or does not exist.
**Procedure**
Ensure that the URI is correct.
## 100003 Too Many Pages Are Pushed into the Page Stack
**Error Message**
Page stack error. The pages are pushed too much.
**Description**
This error code is reported when more than 32 pages are pushed into the page stack.
**Possible Causes**
Too many pages are pushed.
**Procedure**
Delete unnecessary or invalid pages.
## 200002 Incorrect URI
**Error Message**
Uri error. The uri of router is not exist.
**Description**
This error code is reported when the URI of the page to be used for replacement is incorrect or does not exist.
**Possible Causes**
The entered URI is incorrect or does not exist.
**Procedure**
Ensure that the URI is correct.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册