一、组件路由跳转
方式1:navigator组件跳转
方式2:调用API跳转
1.1、打开新页面
使用navigator 组件将 open-type 属性值设置为navigate时 会打开新页面
注意:navigator 无法跳转到已经在 app.json 中已设置的tabbar页面路径 或者是
在navigator中添加 open-type="switchTab"属性
<navigator url="/pages/news/news" open-type="navigate"> <button type="default" class="btn">进入新闻专题</button> </navigator>
1.2、页面重定向
navigator组件将open-type 属性值设为 redirect时 页面会进行重定向
<!-- 页面重定向 -->
<navigator url="/pages/car/car" open-type="redirect"> <button type="default" class="btn">新闻专题</button> </navigator>
注意:页面重定向不会进入历史记录,不支持页面返回
1.3、页面返回
组件 <navigator url="/pages/car/car" open-type="navigate">
在跳转后的页面中可以自定义返回操作
<navigator url="/pages/car/car" open-type="navigate" hover-class="navigator-hover"> <button type="default" class="btn">进入购物车专题</button> </navigator>
在购物车页面 将 open-type属性值设置为 navigateBack
<view> 购物车 <navigator open-type="navigateBack"> <button type="default">返回</button> </navigator> </view>
1.4、Tab切换
tab切换主要用于从当前页面跳转到tabBar中的页面
<navigator url="/pages/news/news" open-type="switchTab"> <button type="default" class="btn">进入新闻专题</button> </navigator>
将open-type属性值设置为 switchTab 可以跳转到tabBar中的页面,跳转后
页面会全部出栈,只留下新的tabBar页面,所以不支持页面返回
1.5、reLaunch
navigator 组件 设置 reLaunch时,会进行重加载,页面全部出栈,只留下新的页面
<navigator url="/pages/news/news" open-type="reLaunch"> <button type="default" class="btn">进入新闻专题</button> </navigator>
重加载可以跳转到任何页面,跳转后页面全部出栈,跳转后的页面不支持页面返回