How do mini program users return to the homepage after authorization
There are many implementation methods, as follows:
1. Use wx.navigateBack(Object object) to close the current page and return to the previous page or multi-level page. You can get the current page stack through getCurrentPages and decide how many levels need to be returned.
Sample code:
// 此处是A页面 wx.navigateTo({ url: 'B?id=1' }) // 此处是B页面 wx.navigateTo({ url: 'C?id=1' }) // 在C页面内 navigateBack,将返回A页面 wx.navigateBack({ delta: 2 })
2. Use wx.navigateTo(Object object) to jump to the page, keep the current page, and jump to a page in the application. But you cannot jump to the tabbar page.
Sample code:
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) }) } })
3. Use wx.redirectTo(Object object) to close the current page and jump to a page within the application. But jumping to the tabbar page is not allowed.
Code example:
wx.redirectTo({ url: 'test?id=1' })
4. Use wx.reLaunch(Object object)Close all pages and open a page within the application
Code example:
wx.reLaunch({ url: 'test?id=1' }) // test Page({ onLoad (option) { console.log(option.query) } })
Recommended learning: Small program development
The above is the detailed content of How do mini program users return to the home page after authorization?. For more information, please follow other related articles on the PHP Chinese website!