在 Uniapp 中,可以使用 uni.navigateTo、uni.redirectTo、uni.reLaunch 和 uni.switchTab 等方法进行页面跳转。\n\n1. uni.navigateTo:保留当前页面,跳转到应用内的某个页面。用户可返回原页面。使用 uni.navigateBack 可以返回原页面。\njavascript\nuni.navigateTo({\n url: '/pages/otherPage/otherPage'\n});\n\n\n2. uni.redirectTo:关闭当前页面,跳转到应用内的某个页面。用户不可返回原页面。\njavascript\nuni.redirectTo({\n url: '/pages/otherPage/otherPage'\n});\n\n\n3. uni.reLaunch:关闭所有页面,打开应用内的某个页面。\njavascript\nuni.reLaunch({\n url: '/pages/otherPage/otherPage'\n});\n\n\n4. uni.switchTab:跳转到应用内的某个 tabBar 页面,并关闭其他所有非 tabBar 页面。\njavascript\nuni.switchTab({\n url: '/pages/tabBarPage/tabBarPage'\n});\n\n\n以上方法中,url 参数是跳转页面的路径,路径以 " / " 开头,可以使用绝对路径或相对路径。如果使用相对路径,可以使用 " ../ " 表示上级目录。\n\n同时,还可以在跳转页面时传递参数,可以通过 url 参数传递参数,也可以使用 query 参数传递参数。例如:\njavascript\nuni.navigateTo({\n url: '/pages/otherPage/otherPage?id=1'\n});\n\n在跳转到 otherPage 页面后,可以通过 this.$route.query.id 获取传递的参数。\n\n需要注意的是,跳转页面时需要在 pages.json 文件中配置相应的路由。

Uniapp 页面跳转方法详解:navigateTo、redirectTo、reLaunch、switchTab

原文地址: https://www.cveoy.top/t/topic/pAPY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录