How do mini program users return to the home page after authorization?

angryTom
Release: 2020-03-20 17:44:40
Original
3846 people have browsed it

How do mini program users return to the home page after authorization?

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
})
Copy after login

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)
    })
  }
})
Copy after login

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'
})
Copy after login

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)
  }
})
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!