@heathenjs/taro-router
v1.1.5
Published
Taro小程序路由库
Maintainers
Readme
@heathenjs/taro-router
Taro小程序路由库
特性
安装
强烈建议与配套的 @heathenjs/taro-router-plugin 一同安装,享受路由自动生成、跳转参数类型校验等能力带来的开发体验
pnpm
pnpm add @heathenjs/taro-router-plugin --save-dev
pnpm add @heathenjs/taro-routeryarn
yarn add @heathenjs/taro-router-plugin --dev
yarn add @heathenjs/taro-routernpm
npm install @heathenjs/taro-router-plugin --save-dev
npm install @heathenjs/taro-router --save解决了什么问题?
小程序进行路由跳转时,手写的 url 无法确认链接正确性,且对于必须带参数的页面(如详情页)不能很好的进行跳转前约束;
- 通过约定的目录结构生产路由跳转方法,通过指定的 API 跳转而不是手写 url;
- 给特定的页面添加 route.config.ts 描述进入该页面时所需参数类型;
页面跳转希望传递自定义对象时无法操作;
- 跳转 API 支持传入任意类型的参数,在跳转到的页面中通过 useParams 获取该参数;
无法描述“从页面返回时”的场景,例如进入某个页面进行操作并返回后,刷新当前页面这种场景难以实现;
- 将跳转行为封装为一个 Promise,当从跳转到的页面返回时,这个 Promise 被 resolve;
- 支持设定当前页面的 BackData,作为上述 Promise 的参数;
路由鉴权写起来相当啰嗦,而且难以和业务代码解耦;
- 页面的 route.config.ts 支持配置页面的 Ext 参数(例如所需的权限码),生成路由时自动写入到跳转 API 中;
- 增加路由中间件功能,在跳转时按顺序进入中间件,则可以添加中间件对上述 Ext 参数结合当前用户身份进行权限校验;
