微信小程序頁面跳轉(zhuǎn)方法總結(jié)

一、JS文件中跳轉(zhuǎn)

  • 1、wx.navigateTo

    • 「保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面,使用wx.navigateBack可以返回到原頁面。」
    wx.navigateTo({
    url: 'page/home/home?user_id=111'
    })
    
  • 2、wx.redirectTo

    • 「關(guān)閉當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面?!?/li>
    wx. redirectTo({
    url: 'page/home/home?user_id=111'
    })
    
  • 3、wx.switchTab

    • 「跳轉(zhuǎn)到 tabBar 頁面,并關(guān)閉其他所有非 tabBar 頁面」
    wx. switchTab({
    url: 'page/index/index'
    })
    
  • 4、wx.navigateBack

    • 「關(guān)閉當(dāng)前頁面,返回上一頁面或多級(jí)頁面??赏ㄟ^ [getCurrentPages()] 獲取當(dāng)前的頁面棧,決定需要返回幾層?!?/li>
    wx.navigateBack({
    delta: 2
    })
    
  • 5、wx.reLaunch

    • 「關(guān)閉所有頁面,打開到應(yīng)用內(nèi)的某個(gè)頁面」
    wx. reLanch({
    url: 'page/index/index'
    })
    

二、wxml 頁面組件跳轉(zhuǎn)「navigator組件」

  • 1.open-type 有效值:navigate --->>對(duì)應(yīng)wx.navigateTo

  • 1.open-type 有效值:redirect --->>對(duì)應(yīng)wx.redirectTo

  • 1.open-type 有效值:switchTab --->>對(duì)應(yīng)wx.switchTab

  • 1.open-type 有效值:reLaunch --->>對(duì)應(yīng)wx.reLaunch

  • 1.open-type 有效值:navigateBack --->>對(duì)應(yīng)wx.navigateBack

  • 1.open-type 有效值:exit----->>退出小程序,target="miniProgram"時(shí)生效

實(shí)例

//1.直接使用
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在當(dāng)前頁打開</navigator>

//2.包裹控件使用
<navigator url="../../redirect/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">
<button>在當(dāng)前頁打開</button>
</navigator>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容