Routing
switchTab
TIP
The API usage is as follows: wx.switchTab(Object object)
- Functional description: Jump to the tabBar page and close all other non-tabBar pages.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| url | string | - | Yes | The path (code package path) of the tabBar page to be jumped (the page to be defined in the tabBar field of app.json), no parameters after the path |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- Sample code:
js
// app.json
{
"tabBar": {
"list": [{
"pagePath": "index",
"text": "home"
},{
"pagePath": "other",
"text": "other"
}]
}
}js
wx.switchTab({
url: '/index'
})reLaunch
TIP
The API usage is as follows: wx.reLaunch(Object object)
- Functional description: Close all pages and open a page in the application.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| url | string | - | Yes | The path (code package path) of the non-tabBar page in the application to be jumped, the path can be followed by parameters, the parameters and the path are separated by ?, the parameter key and the parameter value are connected by =, and different parameters are separated by &; such as 'path?key=value&key2=value2' |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- Sample code:
js
wx.reLaunch({
url: 'test?id=1'
})redirectTo
TIP
The API usage is as follows: wx.redirectTo(Object object)
- Functional description: Close the current page and jump to a page in the application. However, jumping to the tabbar page is not allowed.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| url | string | - | Yes | The path (code package path) of the page in the application to be jumped, the path can be followed by parameters. Parameters and paths are separated by ?, parameter keys and parameter values |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- Sample code:
js
wx.redirectTo({
url: 'test?id=1'
})navigateTo
TIP
The API usage is as follows: wx.navigateTo(Object object)
- Functional description: Keep the current page and jump to a page in the application, but cannot jump to the tabbar page. Use wx.navigateBack to return to the original page. The page stack in the mini program is up to ten layers.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| url | string | - | Yes | The path (code package path) of the non-tabBar page in the application to be jumped, the path can be followed by parameters, the parameters and the path are separated by ?, the parameter key and the parameter value are connected by =, and different parameters are separated by &; such as 'path?key=value&key2=value2' |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- Sample code:
js
wx.navigateTo({
url: 'test?id=1',
})
//test.js
Page({
onLoad: (option){
console.log(option.query)
}
})navigateBack
TIP
The API usage is as follows: wx.navigateBack(Object object)
- Functional description: Close the current page and return to the previous page or multiple pages. You can use getCurrentPages to get the current page stack and decide how many layers to return.
- Parameters and descriptions: Object object。
| Properties | Type | Default value | Required | Description |
|---|---|---|---|---|
| data | number | 1 | No | The number of pages returned. If delta is greater than the number of existing pages, it returns to the homepage. |
| success | Function | - | No | Callback function for successful interface call |
| fail | Function | - | No | Callback function for failed interface call |
| complete | Function | - | No | Callback function for interface call completion (executed regardless of success or failure) |
- Sample code:
js
// Note: When calling navigateTo for navigation, the page that calls this method will be added to the stack, whereas the redirectTo method will not. See the example code below.
// This is page A
wx.navigateTo({
url: 'B?id=1'
})
// This is page B
wx.navigateTo({
url: 'C?id=1'
})
// Perform navigateback within page C will return to page A.
wx.navigateBack({
delta: 2
})EventChannel
Inter-page event communication channel
EventChannel.emit
TIP
The API usage is as follows: EventChannel.emit(string eventName, any args)
- Functional description: Trigger an event
- Parameters and descriptions: string eventName, event name; any args, event parameters.
EventChannel.off
TIP
The API usage is as follows: EventChannel.off(string eventName, EventCallback fn)
- Functional description: Cancel listening to an event. When the second parameter is given, only the given listening function is canceled, otherwise all listening functions are canceled. The usage method is EventChannel.off(string eventName, function fn).
- Parameters and descriptions: string eventName, Event name; function fn, event listening function; any args, triggering event parameters.
EventChannel.on
TIP
The API usage is as follows: EventChannel.on(string eventName, EventCallback fn)
- Functional description: Continuously listen to an event. The usage method is EventChannel.on(string eventName, function fn).
- Parameters and descriptions: string eventName, Event name; function fn, event listening function; any args, triggering event parameters.
EventChannel.once
TIP
The API usage is as follows: EventChannel.once(string eventName, EventCallback fn)
- Functional description: Listen to an event once, and it will become invalid after being triggered. The usage method is EventChannel.once(string eventName, function fn).
- Parameters and descriptions: string eventName, Event name; function fn, event listening function; any args, triggering event parameters.