Instruction file imported from Moonofweisheng/MyCookLikeHOC (
.cursor/rules/route.mdc). Copyright stays with the author.
路由开发规则
基于文件的路由
- 本项目基于@uni-helper/vite-plugin-uni-pages在uni-app 上实现基于文件的路由系统。
- 使用SFC 自定义块用于路由数据,通过添加一个 块到 SFC 中来添加路由元数据。这将会在路由生成后直接添加到路由中,并且会覆盖。
- 在
pages.config.ts文件中可以配置tabbar等全局配置。
布局框架
- 本项目基于@uni-helper/vite-plugin-uni-layouts实现 uni-app 的可定制布局框架。
- 可以结合 vite-plugin-uni-pages 的 route-block 实现指定页面布局。
路由跳转
- 本项目使用uni-mini-router实现路由跳转。
- uni-mini-router 提供2个hooks:
useRouter和useRoute。 - push方法
router.push(target:RouteLocationRaw): void保留当前页面,跳转到应用内的某个页面,相当于使用uni.navigateTo(OBJECT)。 - pushTab方法
router.pushTab(target:RouteLocationRaw): void跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面,相当于使用uni.switchTab(OBJECT)。 - replace方法
router.replace(target:RouteLocationRaw): void关闭当前页面,跳转到应用内的某个页面,相当于使用uni.redirectTo(OBJECT)。 - replaceAll方法
router.replaceAll(target:RouteLocationRaw): void关闭所有页面,打开到应用内的某个页面,相当于使用uni.reLaunch(OBJECT)。 - back方法
router.back(level?: number): void关闭当前页面,返回上一页面或多级页面,相当于使用uni.navigateBack(OBJECT)。