<navigator/>是小程序种的页面链接,其作用和HTML中超链接标签一样,主要控制页面的跳转,<navigator/>属性如下:
由于内容较多,请参考微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/navigator.html
实例代码如下:
<view class="btn-area">
<navigator url="../navigate/navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>
<navigator url="/redirect/redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
<navigator url="/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
</view>
// redirect.js navigator.js
Page({
onLoad: function (options) {
this.setData({
title: options.title
})
}
})
<!-- navigator.wxml -->
<view style="text-align:center"> {{title}} </view>
<view> 点击左上角返回回到之前页面 </view>
<!-- redirect.wxml -->
<view style="text-align:center">{{title}}</view>
<view>点击左上角返回回到上级页面</view>
.navigator-hover {
color:blue;
}
/** 自定义其他点击态样式类 **/
.other-navigator-hover {
color:red;
}
框架为:
执行结果如下: