{"id":13604070,"url":"https://github.com/lblblong/tarojs-router-next","last_synced_at":"2025-04-11T22:32:32.407Z","repository":{"id":49947715,"uuid":"296557520","full_name":"lblblong/tarojs-router-next","owner":"lblblong","description":"Taro 小程序路由库/自动生成带参数类型提示的路由方法/允许传递任意类型、任意大小的参数数据/同步的路由方法调用/koa体验一致的路由中间件","archived":false,"fork":false,"pushed_at":"2024-08-06T03:27:06.000Z","size":9220,"stargazers_count":253,"open_issues_count":10,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T14:47:15.084Z","etag":null,"topics":["react","router","taro","tarojs-router"],"latest_commit_sha":null,"homepage":"https://lblblong.github.io/tarojs-router-next/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lblblong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-18T08:13:06.000Z","updated_at":"2025-01-24T17:12:22.000Z","dependencies_parsed_at":"2023-11-24T05:30:28.470Z","dependency_job_id":"deb5120b-8da3-4f2f-93fc-18066453e720","html_url":"https://github.com/lblblong/tarojs-router-next","commit_stats":{"total_commits":114,"total_committers":4,"mean_commits":28.5,"dds":"0.20175438596491224","last_synced_commit":"721fa687b8b3cc3ab3a33d28776a041d16beb940"},"previous_names":["lblblong/tarojs-router"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lblblong%2Ftarojs-router-next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lblblong%2Ftarojs-router-next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lblblong%2Ftarojs-router-next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lblblong%2Ftarojs-router-next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lblblong","download_url":"https://codeload.github.com/lblblong/tarojs-router-next/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801178,"owners_count":20998331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","router","taro","tarojs-router"],"created_at":"2024-08-01T19:00:39.339Z","updated_at":"2025-04-11T22:32:28.132Z","avatar_url":"https://github.com/lblblong.png","language":"TypeScript","funding_links":[],"categories":["第三方库和组件","TypeScript"],"sub_categories":["Taro1"],"readme":"# tarojs-router-next\n\n[![](https://img.shields.io/npm/v/tarojs-router-next.svg?style=flat-square)](https://www.npmjs.com/package/tarojs-router-next)\n[![](https://img.shields.io/npm/l/tarojs-router-next.svg?style=flat-square)](https://www.npmjs.com/package/tarojs-router-next)\n[![](https://img.shields.io/npm/dt/tarojs-router-next.svg?style=flat-square)](https://www.npmjs.com/package/tarojs-router-next)\n\n它是一个小巧的 [Taro(小程序)](https://github.com/nervjs/taro) 路由库，为你提供以下特性：\n\n- 自动生成带参数类型提示的路由方法\n- 允许传递任意类型、任意大小的参数数据\n- 同步的路由方法调用\n- koa 体验一致的路由中间件\n\n## 快速开始\n\n[使用文档](https://lblblong.github.io/tarojs-router-next/guide/quike/start)，[API 文档](https://lblblong.github.io/tarojs-router-next/api/router)\n\n[Demo（代码）](https://github.com/lblblong/tarojs-router-next/tree/master/examples)，[Demo（微信开发者工具打开）](https://developers.weixin.qq.com/s/2CcFkJmo7Dpb)\n\n#### 安装核心依赖\n\n```shell\n$ npm install --save tarojs-router-next\n```\n\n#### 安装路由方法自动生成插件\n\n```shell\n$ npm install --dev tarojs-router-next-plugin\n```\n\n在 [编译配置(/config/index.js)](https://taro-docs.jd.com/docs/config-detail#plugins) 的 plugins 字段中引入插件：\n\n```typescript\nconst config = {\n  plugins: ['tarojs-router-next-plugin'],\n}\n```\n\n## 解决什么问题\n\n1. 路由跳转的页面 url 没有类型提示容易输错\n2. 路由传参需要手动拼接参数、无法携带任意类型、任意大小的数据\n3. 路由方法是异步的，页面通过 `EventChannel` 通信，事件的回调方法可读性差、耦合度高、只能在回调内部处理异常\n4. 路由跳转的鉴权等实现起来比较麻烦\n\n## 如何解决\n\n**1. 路由跳转的页面 url 没有类型提示容易输错**\n\ntarojs-router-next 不需要使用者手写页面 url，它会监听项目 `src/pages` 内容变化，自动为使用者生成对应的路由方法并附加到 [Router](https://lblblong.github.io/tarojs-router-next/api/router) 类上，比如以下列子：\n\n左边的页面结构会生成右边的 [Router.to\\*\\*](https://lblblong.github.io/tarojs-router-next/api/router#to-options-) 系列方法，全都挂在 [Router](https://lblblong.github.io/tarojs-router-next/api/router) 类上\n\n![](https://lblblong.github.io/tarojs-router-next/images/code1.png)\n\n**2. 路由传参需要手动拼接参数、无法携带任意类型、任意大小的数据**\n\ntarojs-router-next 允许直接传递一个对象给 `params`，它会把 `params` 展开拼接到 `url` 后面。并且还可以接收一个 `data` 参数，`data` 可以传递任意类型、任意大小的数据。\n\n![](https://lblblong.github.io/tarojs-router-next/images/code2.gif)\n\n**3. 路由方法是异步的，页面通过 `EventChannel` 通信，事件的回调方法可读性差、耦合度高、只能在回调内部处理异常**\n\ntarojs-router-next 的路由跳转会返回一个 `Promise`，可以用 `async/await` 写出同步代码，详细参考 [同步的路由方法](https://lblblong.github.io/tarojs-router-next/guide/quike/sync-router)\n\n**4. 路由跳转的鉴权等实现起来比较麻烦**\n\n自己实现路由的鉴权是比较麻烦的事情，而 tarojs-router-next 提供非常易于理解的路由中间件功能，详细参考 [路由中间件](https://lblblong.github.io/tarojs-router-next/guide/quike/middleware)\n\n## 平台与框架支持\n\n#### 框架\n\n支持所有 `Taro` 可支持的框架（`React`、`Vue`、`Vue3`、`Nerv`）\n\n#### 小程序\n\n理论上支持所有 `Taro` 可支持的小程序平台，目前已在 `微信小程序`、`QQ小程序`、`支付宝小程序` 测试通过\n\n#### H5\n\n支持\n\n#### React Native\n\n暂不支持\n\n## 友情推荐\n\n#### Taroify\n\n地址：https://github.com/mallfoundry/taroify\n\nTaroify 是移动端组件库 Vant 的 Taro 版本，两者基于相同的视觉规范，提供一致的 API 接口，助力开发者快速搭建小程序应用。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flblblong%2Ftarojs-router-next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flblblong%2Ftarojs-router-next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flblblong%2Ftarojs-router-next/lists"}