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
| 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. |
| 100001 | If UI execution context not found. |
| 100002 | If the uri is not exist. |
| 100003 | If the pages are pushed too much. |
**Example**
...
...
@@ -54,8 +54,8 @@ try {
data1:'message',
data2:{
data3:[123,456,789]
},
},
}
}
})
.then(()=>{
// success
...
...
@@ -89,9 +89,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| 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. |
| 100001 | If UI execution context not found. |
| 100002 | If the uri is not exist. |
| 100003 | If the pages are pushed too much. |
**Example**
...
...
@@ -103,8 +103,8 @@ try {
data1:'message',
data2:{
data3:[123,456,789]
},
},
}
}
},(err)=>{
if(err){
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
| 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. |
| 100001 | If UI execution context not found. |
| 100002 | If the uri is not exist. |
| 100003 | If the pages are pushed too much. |
**Example**
...
...
@@ -157,8 +157,8 @@ try {
data1:'message',
data2:{
data3:[123,456,789]
},
},
}
}
},router.RouterMode.Standard)
.then(()=>{
// success
...
...
@@ -193,9 +193,9 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| 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. |
| 100001 | If UI execution context not found. |
| 100002 | If the uri is not exist. |
| 100003 | If the pages are pushed too much. |
**Example**
...
...
@@ -207,8 +207,8 @@ try {
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}`);
...
...
@@ -247,8 +247,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
| 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | If the uri is not exist. |
**Example**
...
...
@@ -257,8 +257,8 @@ try {
router.replaceUrl({
url:'pages/detail',
params:{
data1:'message',
},
data1:'message'
}
})
.then(()=>{
// success
...
...
@@ -292,8 +292,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
| 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | If the uri is not exist. |
**Example**
...
...
@@ -302,8 +302,8 @@ try {
router.replaceUrl({
url:'pages/detail',
params:{
data1:'message',
},
data1:'message'
}
},(err)=>{
if(err){
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
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
| 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | If the uri is not exist. |
**Example**
...
...
@@ -354,8 +354,8 @@ try {
router.replaceUrl({
url:'pages/detail',
params:{
data1:'message',
},
data1:'message'
}
},router.RouterMode.Standard)
.then(()=>{
// success
...
...
@@ -390,8 +390,8 @@ For details about the error codes, see [Router Error Codes](../errorcodes/errorc
| ID | Error Message|
| --------- | ------- |
| 100001 | Internal error. |
| 200002 | Uri error. The uri of router is not exist. |
| 100001 | If UI execution context not found, only throw in standard system. |
| 200002 | If the uri is not exist. |
**Example**
...
...
@@ -400,8 +400,8 @@ try {
router.replaceUrl({
url:'pages/detail',
params:{
data1:'message',
},
data1:'message'
}
},router.RouterMode.Standard,(err)=>{
if(err){
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.
**Example**
```js
varsize=router.getLength();
letsize=router.getLength();
console.log('pages stack size = '+size);
```
...
...
@@ -486,7 +486,7 @@ Obtains state information about the current page.
**Example**
```js
varpage=router.getState();
letpage=router.getState();
console.log('current index = '+page.index);
console.log('current name = '+page.name);
console.log('current path = '+page.path);
...
...
@@ -498,11 +498,11 @@ Describes the page routing state.
| 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.|
| 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.|
// 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.