這篇文章主要介紹了微信小程序 空白頁(yè)重定向解決辦法的相關(guān)資料,需要的朋友可以參考下
微信小程序 空白頁(yè)重定向解決辦法
在剛開始的時(shí)候?qū)⑿〕绦虻娜肟谖募苯又赶騮abbar 的首頁(yè),此時(shí)出現(xiàn)問題:二維碼掃描,第一次不關(guān)閉首頁(yè),第二次進(jìn)入時(shí);不會(huì)經(jīng)過onLoad過程解析scene參數(shù);
官方中解釋:tabbar跳轉(zhuǎn)方式觸發(fā)的生命周期是 onShow,不經(jīng)過onLoad,下圖:
此時(shí),和小伙伴討論重定向問題時(shí),想到用類似的方法可以做到,就立馬實(shí)行:
app.json中加pages/index/index(入口文件),pages/home/home(tabbar頁(yè)面主頁(yè)),pages/detail/detail(詳情頁(yè));pages/exclusive/exclusive
在index.js中 onLoad處理:
/** * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載 */ onLoad: function (options) { // 入口文件 決定進(jìn)入哪個(gè)頁(yè)面 console.log('入口文件,參數(shù)scene,值detail%2C1127') var scene = options.scene; //掃碼進(jìn)入有此參數(shù) var scene = decodeURIComponent(options.scene); if (scene) { //'scene=detail%2C1127' 分隔符, 測(cè)試時(shí)為 , 號(hào);真機(jī)時(shí)為%2C 原因是url編碼,但是使用decodeURI()解析不出來,所以走了兼容 let info_arr = []; info_arr = scene.split(','); //console.log(info_arr) let _type = info_arr[0]; let id = info_arr[1]; if (_type == 'detail') { wx.redirectTo({ url: `../detail/detail?id=${id}`, }) } else if (_type == 'exclusive') { wx.redirectTo({ url: `../exclusive/exclusive?id=${id}`, }) } }else{ wx.switchTab({ url: '../home/home', }) } },登錄后復(fù)制
此時(shí),完美解決 從 掃碼-->home-->detail;再次掃碼-->home 不能到-->detail的問題;
此時(shí) 掃碼-->index(redirectTo)-->detail;再次掃碼-->index(redirectTo)-->detail的問題;越過home頁(yè)面
由于home頁(yè)面有大量的請(qǐng)求,不適宜用redirectTo;所以此方法算是折中的選擇了
以上就是微信小程序中空白頁(yè)重定向的問題解決辦法分享的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注愛掏網(wǎng) - it200.com其它相關(guān)文章!