May 19, 2021 WeChat Mini Program Development Document
Keep the current page and jump to a page within the app. H owever, you cannot jump to the tabbar page. U se wx.navigateBack to return to the original page. The page stack in a small program can be up to ten levels.
Property | Type | The default | Required | Description |
---|---|---|---|---|
Url | string | Is |
The path (code package path) of the non-tabBar page within the app that needs to be jumped, and the path can be followed by parameters.
The parameters are separated from the
=
?
the keys are connected to the parameter values, and the different parameters are separated by the values of the parameters, such as 'path?key=value=value=key2=value2'
&
|
|
events | Object | Whether | An inter-page communication interface that listens for data that is sent to the current page by an open page. Base library 2.7.3 starts to support. | |
success | function | Whether | The interface calls a successful callback function | |
fail | function | Whether | The interface calls the failed callback function | |
complete | function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Attributes | type | illustrate |
---|---|---|
eventChannel | EventChannel | Communicate with the open page |
wx.navigateTo({
url: 'test?id=1',
events: {
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
acceptDataFromOpenedPage: function(data) {
console.log(data)
},
someEvent: function(data) {
console.log(data)
}
...
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
}
})
//test.js
Page({
onLoad: function(option){
console.log(option.query)
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
eventChannel.emit('someEvent', {data: 'test'});
// 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
eventChannel.on('acceptDataFromOpenerPage', function(data) {
console.log(data)
})
}
})