提交 a10af0bd 编写于 作者: E ester.zhou

Update docs (12872)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 4da793b5
# Page Routing # @ohos.router
The **Router** module provides APIs to access pages through URLs. You can use the APIs to navigate to a specified page in an application, replace the current page with another one in an application, and return to the previous page or a specified page. The **Router** module provides APIs to access pages through URLs. You can use the APIs to navigate to a specified page in an application, replace the current page with another one in an application, and return to the previous page or a specified page.
...@@ -40,9 +40,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -40,9 +40,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found. |
| 100002 | Uri error. The uri of router is not exist. | | 100002 | If the uri is not exist. |
| 100003 | Page stack error. The pages are pushed too much. | | 100003 | If the pages are pushed too much. |
**Example** **Example**
...@@ -54,8 +54,8 @@ try { ...@@ -54,8 +54,8 @@ try {
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
}) })
.then(() => { .then(() => {
// success // success
...@@ -89,9 +89,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -89,9 +89,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found. |
| 100002 | Uri error. The uri of router is not exist. | | 100002 | If the uri is not exist. |
| 100003 | Page stack error. The pages are pushed too much. | | 100003 | If the pages are pushed too much. |
**Example** **Example**
...@@ -103,8 +103,8 @@ try { ...@@ -103,8 +103,8 @@ try {
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
}, (err) => { }, (err) => {
if (err) { if (err) {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
...@@ -143,9 +143,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -143,9 +143,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found. |
| 100002 | Uri error. The uri of router is not exist. | | 100002 | If the uri is not exist. |
| 100003 | Page stack error. The pages are pushed too much. | | 100003 | If the pages are pushed too much. |
**Example** **Example**
...@@ -157,8 +157,8 @@ try { ...@@ -157,8 +157,8 @@ try {
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
}, router.RouterMode.Standard) }, router.RouterMode.Standard)
.then(() => { .then(() => {
// success // success
...@@ -193,9 +193,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -193,9 +193,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found. |
| 100002 | Uri error. The uri of router is not exist. | | 100002 | If the uri is not exist. |
| 100003 | Page stack error. The pages are pushed too much. | | 100003 | If the pages are pushed too much. |
**Example** **Example**
...@@ -207,8 +207,8 @@ try { ...@@ -207,8 +207,8 @@ try {
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
}, router.RouterMode.Standard, (err) => { }, router.RouterMode.Standard, (err) => {
if (err) { if (err) {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
...@@ -247,8 +247,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -247,8 +247,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | Uri error. The uri of router is not exist. | | 200002 | If the uri is not exist. |
**Example** **Example**
...@@ -257,8 +257,8 @@ try { ...@@ -257,8 +257,8 @@ try {
router.replaceUrl({ router.replaceUrl({
url: 'pages/detail', url: 'pages/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}) })
.then(() => { .then(() => {
// success // success
...@@ -292,8 +292,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -292,8 +292,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | Uri error. The uri of router is not exist. | | 200002 | If the uri is not exist. |
**Example** **Example**
...@@ -302,8 +302,8 @@ try { ...@@ -302,8 +302,8 @@ try {
router.replaceUrl({ router.replaceUrl({
url: 'pages/detail', url: 'pages/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}, (err) => { }, (err) => {
if (err) { if (err) {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
...@@ -344,8 +344,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -344,8 +344,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | Uri error. The uri of router is not exist. | | 200002 | If the uri is not exist. |
**Example** **Example**
...@@ -354,8 +354,8 @@ try { ...@@ -354,8 +354,8 @@ try {
router.replaceUrl({ router.replaceUrl({
url: 'pages/detail', url: 'pages/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}, router.RouterMode.Standard) }, router.RouterMode.Standard)
.then(() => { .then(() => {
// success // success
...@@ -390,8 +390,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -390,8 +390,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | Uri error. The uri of router is not exist. | | 200002 | If the uri is not exist. |
**Example** **Example**
...@@ -400,8 +400,8 @@ try { ...@@ -400,8 +400,8 @@ try {
router.replaceUrl({ router.replaceUrl({
url: 'pages/detail', url: 'pages/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}, router.RouterMode.Standard, (err) => { }, router.RouterMode.Standard, (err) => {
if (err) { if (err) {
console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`replaceUrl failed, code is ${err.code}, message is ${err.message}`);
...@@ -465,7 +465,7 @@ Obtains the number of pages in the current stack. ...@@ -465,7 +465,7 @@ Obtains the number of pages in the current stack.
**Example** **Example**
```js ```js
var size = router.getLength(); let size = router.getLength();
console.log('pages stack size = ' + size); console.log('pages stack size = ' + size);
``` ```
...@@ -486,7 +486,7 @@ Obtains state information about the current page. ...@@ -486,7 +486,7 @@ Obtains state information about the current page.
**Example** **Example**
```js ```js
var page = router.getState(); let page = router.getState();
console.log('current index = ' + page.index); console.log('current index = ' + page.index);
console.log('current name = ' + page.name); console.log('current name = ' + page.name);
console.log('current path = ' + page.path); console.log('current path = ' + page.path);
...@@ -498,11 +498,11 @@ Describes the page routing state. ...@@ -498,11 +498,11 @@ Describes the page routing state.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Description | | Name | Type | Mandatory| Description |
| ----- | ------ | ---------------------------------- | | ----- | ------ | ---- | ------------------------------------------------------------ |
| index | number | Index of the current page in the stack. The index starts from 1 from the bottom to the top of the stack.| | index | number | Yes | Index of the current page in the stack. The index starts from 1 from the bottom to the top of the stack.|
| name | string | Name of the current page, that is, the file name. | | name | string | No | Name of the current page, that is, the file name. |
| path | string | Path of the current page. | | path | string | Yes | Path of the current page. |
## router.enableBackPageAlert<sup>9+</sup> ## router.enableBackPageAlert<sup>9+</sup>
...@@ -524,7 +524,7 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc ...@@ -524,7 +524,7 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message| | ID | Error Message|
| --------- | ------- | | --------- | ------- |
| 100001 | Internal error. | | 100001 | If UI execution context not found. |
**Example** **Example**
...@@ -590,7 +590,7 @@ Describes the page routing options. ...@@ -590,7 +590,7 @@ Describes the page routing options.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.| | 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 target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.| | params | object | No | Data that needs to be passed to the target page during redirection. The target page can use **router.getParams()** to obtain the passed parameters, for example, **this.keyValue** (**keyValue** is the value of a key in **params**). In the web-like paradigm, these parameters can be directly used on the target page. If the field specified by **key** already exists on the target page, the passed value of the key will be displayed.|
> **NOTE** > **NOTE**
...@@ -602,9 +602,9 @@ Enumerates the routing modes. ...@@ -602,9 +602,9 @@ Enumerates the routing modes.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Description | | Name | Description |
| -------- | ---------------------------------------- | | -------- | ------------------------------------------------------------ |
| 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. | | 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
...@@ -618,8 +618,8 @@ export default { ...@@ -618,8 +618,8 @@ export default {
router.push({ router.push({
url: 'pages/detail/detail', url: 'pages/detail/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}); });
} }
} }
...@@ -642,18 +642,18 @@ import router from '@ohos.router' ...@@ -642,18 +642,18 @@ import router from '@ohos.router'
@Entry @Entry
@Component @Component
struct Index { struct Index {
async routePage() { async routePage() {
let options = { let options = {
url: 'pages/second', url: 'pages/second',
params: { params: {
text: 'This is the value on the first page.', text: 'This is the value on the first page.',
data: { data: {
array: [12, 45, 78] array: [12, 45, 78]
}, }
} }
} }
try { try {
await router.push(options) await router.pushUrl(options)
} catch (err) { } catch (err) {
console.info(` fail callback, code: ${err.code}, msg: ${err.msg}`) console.info(` fail callback, code: ${err.code}, msg: ${err.msg}`)
} }
...@@ -661,18 +661,18 @@ struct Index { ...@@ -661,18 +661,18 @@ struct Index {
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('This is the first page.') Text('This is the first page.')
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('next page') Text('next page')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
.margin({ top: 20 }) .margin({ top: 20 })
.backgroundColor('#ccc') .backgroundColor('#ccc')
.onClick(() => { .onClick(() => {
this.routePage() this.routePage()
}) })
} }
.width('100%') .width('100%')
...@@ -704,7 +704,7 @@ struct Second { ...@@ -704,7 +704,7 @@ struct Second {
this.secondData = (this.data.array[1]).toString() this.secondData = (this.data.array[1]).toString()
}) })
.margin({top:20}) .margin({top:20})
Text('Value from the first page '+'' + this.secondData) Text(`This is the data passed from the first page: ${this.secondData}`)
.fontSize(20) .fontSize(20)
.margin({top:20}) .margin({top:20})
.backgroundColor('red') .backgroundColor('red')
...@@ -741,8 +741,8 @@ router.push({ ...@@ -741,8 +741,8 @@ router.push({
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
}); });
``` ```
## router.push<sup>(deprecated)</sup> ## router.push<sup>(deprecated)</sup>
...@@ -772,8 +772,8 @@ router.push({ ...@@ -772,8 +772,8 @@ router.push({
data1: 'message', data1: 'message',
data2: { data2: {
data3: [123, 456, 789] data3: [123, 456, 789]
}, }
}, }
},router.RouterMode.Standard); },router.RouterMode.Standard);
``` ```
...@@ -799,8 +799,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl<s ...@@ -799,8 +799,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl<s
router.replace({ router.replace({
url: 'pages/detail', url: 'pages/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}); });
``` ```
...@@ -812,7 +812,7 @@ Replaces the current page with another one in the application and destroys the c ...@@ -812,7 +812,7 @@ Replaces the current page with another one in the application and destroys the c
This API is deprecated since API version 9. You are advised to use [replaceUrl<sup>9+</sup>](#routerreplaceurl9) instead. 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 **System capability**: SystemCapability.ArkUI.ArkUI.Lite
**Parameters** **Parameters**
...@@ -827,8 +827,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl<s ...@@ -827,8 +827,8 @@ This API is deprecated since API version 9. You are advised to use [replaceUrl<s
router.replace({ router.replace({
url: 'pages/detail/detail', url: 'pages/detail/detail',
params: { params: {
data1: 'message', data1: 'message'
}, }
}, router.RouterMode.Standard); }, router.RouterMode.Standard);
``` ```
......
...@@ -46,7 +46,7 @@ struct PositionExample1 { ...@@ -46,7 +46,7 @@ struct PositionExample1 {
.fontSize(16) .fontSize(16)
.backgroundColor(0xFFE4C4) .backgroundColor(0xFFE4C4)
// To arrange the child components from left to right, set direction of the parent container to Direction.Auto or Direction.Ltr, or leave it to the default value. // To arrange the child components from left to right, set direction of the parent container to Direction.Ltr.
Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row() { Row() {
Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
...@@ -55,19 +55,19 @@ struct PositionExample1 { ...@@ -55,19 +55,19 @@ struct PositionExample1 {
Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
} }
.width('90%') .width('90%')
.direction(Direction.Auto) .direction(Direction.Ltr)
// To arrange the child components from right to left, set direction of the parent container to Direction.Rtl. // To arrange the child components from right to left, set direction of the parent container to Direction.Rtl.
Row() { Row() {
Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
} }
.width('90%') .width('90%')
.direction(Direction.Rtl) .direction(Direction.Rtl)
} }
} }
.width('100%').margin({ top: 5 }).direction(Direction.Rtl) .width('100%').margin({ top: 5 })
} }
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册