一、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.navigateTo1.open-type 有效值:redirect --->>對(duì)應(yīng)
wx.redirectTo1.open-type 有效值:switchTab --->>對(duì)應(yīng)
wx.switchTab1.open-type 有效值:reLaunch --->>對(duì)應(yīng)
wx.reLaunch1.open-type 有效值:navigateBack --->>對(duì)應(yīng)
wx.navigateBack1.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>