Three ways to jump to WeChat Mini Program page

In order not to cause trouble for users when using the Mini Program, the WeChat Mini Program stipulates that the page path can only be five layers, please try to avoid multi-level interaction.
If the page jumps, it involves multiple page levels

The first one: wx.navigateTo(OBJECT)
retains the current page, jumps to a certain page in the application, and uses wx.navigateBack to return to the original page.

Description of OBJECT parameters:

The parameter type is required to indicate that
url String is the path of the in-app page that needs to be redirected, and parameters can be added after the path. Parameters and paths are separated by ?, parameter keys and parameter values ​​are connected by =, and different parameters are separated by &; such as 'path?key=value&key2=value2'

   goto: function (e) {
      let a =e.currentTarget.dataset.id
        wx.navigateTo({
               url: '../index/index?id'+id
        })
  }
 
 

Another page receives parameters in onLoad

 onLoad(options) {
    // console.log(options.id);
    let id =options.id
    
  },

 

The second method: wx.redirectTo(OBJECT)
closes the current page and jumps to a page in the application.

Description of OBJECT parameters:

The parameter type is required to indicate that
url String is the path of the in-app page that needs to be redirected

   goto: function (e) {
      let a =e.currentTarget.dataset.id
        wx.navigateTo({
               url: '../index/index?id'+id
        })
  }

The third method: wx.navigateBack(OBJECT)
closes the current page and returns to the previous page or multi-level pages. The current page stack can be obtained through getCurrentPages()) to determine how many layers need to be returned.
Description of OBJECT parameters:

Parameter type default value description
delta Number 1 The number of pages returned, if delta is greater than the number of existing pages, it will return to the home page.

 onLoad: function(options) {
        var pages = getCurrentPages()
        var num = pages.length
        navigateBack:function(){
            wx.navigateBack({
                 delta: num
            })
        }
 }

Guess you like

Origin blog.csdn.net/xybhua/article/details/128793168