WeChat Mini Program API Navigation


1. wx.navigateTo(OBJECT)


Keep the current page and jump to a page in the application. Use wx.navigateBack to return to the original page.

OBJECT parameter description:

Sample code:

wx.navigateTo({
  url: 'test?id=1'
})
//test.js
Page({
  onLoad: function(option){
    console.log(option.query)
  }
})

Note: In order to prevent users from using small To cause trouble when programming, we stipulate that the page path can only be five levels. Please try to avoid multi-level interactions.


2. wx.redirectTo(OBJECT)


Close the current page and jump to a page within the application.

OBJECT Parameter description:

QQ截图20170208132404.png

##Sample code:

wx.redirectTo({
  url: 'test?id=1'
})


3. wx.navigateBack(OBJECT)


Close the current page and return to the previous page or multi-level page. You can get the current page stack through

getCurrentPages()) to determine how many layers need to be returned.

OBJECT parameter description:

ParameterTypeDefault valueDescription##delta
Number1The number of pages returned, if delta If it is greater than the number of existing pages, return to the home page.
Sample code:

// 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码

// 此处是A页面
wx.navigateTo({
  url: 'B?id=1'
})

// 此处是B页面
wx.redirectTo({
  url: 'C?id=1'
})

// 在C页面内 navigateBack,将返回A页面
wx.navigateBack()


4. wx.switchTab(OBJECT)

Jump to the tabBar page and close all other non-tabBar pages

OBJECT parameter description:

QQ截图20170208132418.png

Sample code:

{
  "tabBar": {
    "list": [{
      "pagePath": "index",
      "text": "首页"
    },{
      "pagePath": "other",
      "text": "其他"
    }]
  }
}
wx.switchTab({
  url: '/index'
})

##Bug & Tip

tip
    : wx.navigateTo and wx.redirectTo do not allow jumping to the tabbar page, only wx.switchTab can be used to jump to the tabbar page