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:
##Sample code:
wx.redirectTo({ url: 'test?id=1' })
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:
Type | Default value | Description | |
---|---|---|---|
Number | 1 | The number of pages returned, if delta If it is greater than the number of existing pages, return to the home page. |
// 注意:调用 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)
OBJECT parameter description:
Sample code:
{
"tabBar": {
"list": [{
"pagePath": "index",
"text": "首页"
},{
"pagePath": "other",
"text": "其他"
}]
}
}
wx.switchTab({
url: '/index'
})
##Bug & 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