參考官方文檔:路由
https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html
//保留當前頁面,跳轉到應用內的某個頁面
wx.navigateTo({
url: 'home?cid=1'
})
//關閉當前頁面,跳轉到應用內的某個頁面
wx.redirectTo({
url: 'home?cid=1'
})
//關閉所有頁面,打開到應用內的某個頁面。
wx.reLaunch({
url: 'home?cid=1'
})
//跳轉到 tabBar 頁面,並關閉其他所有非 tabBar 頁面
wx.switchTab({
url: '/home'
})
關閉當前頁面,返回上一頁面或多級頁面。可通過 [`getCurrentPages`]獲取當前的頁面棧,決定需要返回幾層。
// 此處是A頁面
wx.navigateTo({
url: 'B?id=1'
})
// 此處是B頁面
wx.navigateTo({
url: 'C?id=1'
})
// 在C頁面內 navigateBack,將返回A頁面
wx.navigateBack({
delta: 2
})
跳轉頁面傳遞數組參數必須序列化
let categoryArr=[1,2,3,4,5]
category = JSON.stringify(categoryArr) //取子集分類 數組傳遞需要序列化
wx.navigateTo({
url: `../jumpPage/home/?cate= ${category} `,
})
接收頁面也要序列化參數
onLoad: function (options) {
let category = JSON.parse(options.cate);
console.log(category)
}
參數值過長接收時候內容不全得問題
//傳參
wx.navigateTo({//wx.redirectTo、wx.reLaunch
url: '../details/details?id=' + encodeURIComponent(id)
//接收
onLoad(options) {
var id = decodeURIComponent(options.id);
}