uniapp路由跳转

632 阅读1分钟

在uniapp中,可以使用uni-app提供的路由API来实现页面跳转和路由管理。 1. 页面跳转:
使用uni.navigateTo可以实现页面跳转,并且可以在新页面返回上一页。

uni.navigateTo({  
  url'/pages/otherPage'  
})  

2. 带参数跳转:
如果需要在跳转时传递参数,可以将参数作为url的查询参数进行传递。

uni.navigateTo({  
  url'/pages/otherPage?id=123'  
})  

在被跳转页面的onLoad生命周期函数中,可以通过this.$route.query获取参数。
3. 替换当前页面:
如你想要替换当前页面而不是创建新页面,可以使用uni.redirectTo实现页面重定向。
示例代码:

uni.redirectTo({  
  url'/pages/otherPage'  
})  

4. 返回上一页:
使用uni.navigateBack可以返回到上一页。

uni.navigateBack()  

5. 跳转到指定页面:
如果想要跳转到应用中的某个特定页面,关闭其他所有页面,相当于应用重新启动可以使用uni.reLaunch

uni.reLaunch({  
  url'/pages/home'  
})  

6.跳转到TabBar页面:如果你的应用有TabBar导航,可以使用uni.switchTab方法跳转到TabBar页面。

uni.switchTab({  
     url'/pages/home'  
   })