Jump to js file
1, wx. NavigateTo
Leave the current page and jump to a non-Tabbar page in the app. Use wx.navigateBack to return to the original page. The applets stack up to ten pages, after which the buttons do not respond. Parameters that
//***************** Current page ***************************
wx.navigateTo({
url: 'test? id=1'.events: {
// Adds a listener to the specified event to get data from the opened page to the current page
acceptDataFromOpenedPage: function(data) {
console.log(data)
},
someEvent: function(data) {
console.log(data)
}
...
},
success: function(res) {
// Send data to the opened page via eventChannel
res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test'})}})/ / * * * * * * * * * * * * * * * * * is opened page * * * * * * * * * * * * * * * * * * * * * * * * * * *
Page({
onLoad: function(option){
console.log(option.id)
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
eventChannel.emit('someEvent', {data: 'test'});
// Listen for acceptDataFromOpenerPage events to get data sent from the previous page to the current page via eventChannel
eventChannel.on('acceptDataFromOpenerPage'.function(data) {
console.log(data)
})
}
})
Copy the code
2, wx. RedirectTo
Close the current page and jump to a non-Tabbar page in the app. Parameters that
/ / the current page
wx.redirectTo({ url: 'test? id=1' })
// Open the page
Page({
onLoad: function(option){
console.log(option.id)
}
})
Copy the code
3, wx. SwitchTab
Jump to the tabBar page and close all other non-Tabbar pages. Parameters that
/ / the current page
wx.switchTab({ url: '/index' })
Copy the code
4, wx. ReLaunch
Close all pages and open to a page within the app. Parameters that
/ / the current page
wx.reLaunch({ url: 'test? id=1' })
// Open the page
Page({
onLoad: function(option){
console.log(option.id)
}
})
Copy the code
5, wx. NavigateBack
Close the current page and return to the previous page or multi-level page. You can use getCurrentPages to get the current page stack and determine how many layers you need to return. Parameters that
/ / the current page
wx.navigateBack({
delta: 2 // The number of pages returned, if delta is greater than the number of existing pages, return to the home page.
})
Copy the code
6, wx. NavigateToMiniProgram
Open another small program. Parameters that
/ / the current page
wx.navigateToMiniProgram({
appId: ' './ / required
path: 'page/index/index? id=123'.extraData: {// The data that needs to be passed to the target applet. The target applet can get this data in app. onLaunch, app.onshow.
foo: 'bar'
},
envVersion: 'develop'.success(res) {
// Open successfully}})Copy the code
Jump to the WXML page
Parameters that
<view class="btn-area">
<navigator url="/page/navigate/navigate? title=navigate">Jump to a new page</navigator>
<navigator url=".. /.. /redirect/redirect/redirect? title=redirect" open-type="redirect">Opens on the current page</navigator>
<navigator url="/page/index/index" open-type="switchTab">Switch the Tab</navigator>
<navigator target="miniProgram" open-type="navigate" app-id="" path="" extra-data="" version="release">Open the bound applet</navigator>
</view>
Copy the code
Get route parameters:
Page({
onLoad: function(options) {
this.setData({
title: options.title
})
}
})
Copy the code