1.导航组件(声明式导航)
<navigator target="self" open-type="navigate" url="/pages/index01/index01">
<button>跳转-navigate</button>
</navigator>
<navigator target="self" open-type="redirect" url="/pages/list/list">
<button>跳转-redirect</button>
</navigator>
<navigator target="self" open-type="switchTab" url="/pages/list/list">
<button>跳转-switchTab</button>
</navigator>
<navigator target="self" open-type="reLaunch" url="/pages/index01/index01">
<button>跳转-reLaunch</button>
</navigator>
2.路由API(编程式导航)
wx.switchTab({
url: '../list/list',
})
3.导航传参
组件传参:在路径后问号拼接
<navigator target="self" open-type="navigate" url="/pages/index01/index01?title=hello&id=99">
<button>跳转-navigate</button>
</navigator>
api传参:
wx.navigateTo({
// url: '../index01/index01?id='+id+'&name='+name
url:`../index01/index01?id=${id}&name=${name}`
})
4.接收导航传参
在跳转到的页面里的onLoad函数里通过options形参接收
A-B 在B的onload接
onLoad(options){
console.log(options)
},
/注意: 跳转到tabber页面时。无法接参
<