{"id":15292533,"url":"https://github.com/monajs/mona-react-router","last_synced_at":"2026-05-08T14:04:18.293Z","repository":{"id":57302847,"uuid":"144106291","full_name":"monajs/mona-react-router","owner":"monajs","description":"React-router","archived":false,"fork":false,"pushed_at":"2020-01-07T09:06:20.000Z","size":93,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T05:11:20.702Z","etag":null,"topics":["mo-react-router","mona","monajs","react-router","router"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monajs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-09T05:47:47.000Z","updated_at":"2019-12-30T03:10:11.000Z","dependencies_parsed_at":"2022-09-20T17:21:07.164Z","dependency_job_id":null,"html_url":"https://github.com/monajs/mona-react-router","commit_stats":null,"previous_names":["func-star/mo-react-router"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monajs%2Fmona-react-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monajs%2Fmona-react-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monajs%2Fmona-react-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monajs%2Fmona-react-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monajs","download_url":"https://codeload.github.com/monajs/mona-react-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245249210,"owners_count":20584497,"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":["mo-react-router","mona","monajs","react-router","router"],"created_at":"2024-09-30T16:18:37.440Z","updated_at":"2026-01-05T21:10:21.127Z","avatar_url":"https://github.com/monajs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 轻量赋能版 react-router\n\n摒弃同类产品的劣根，汲取优秀产品的精华，结合数据管理的优势，打造出轻量实用幸福的产品，为react-router更好的赋能！！\n\n[![npm](https://img.shields.io/npm/v/@monajs/react-router.svg?style=flat-square)](https://www.npmjs.com/package/@monajs/react-router) [![npm](https://img.shields.io/npm/dt/@monajs/react-router.svg?style=flat-square)](https://www.npmjs.com/package/@monajs/react-router)\n\n## 大致介绍\n\n这款轻量版 react-router 是基于 history api 和 hash 实现的，用户可以根据业务场景和需求选择 router 类型。\n\u003e router 实现可以参考 [对前端路由选择的思考](https://github.com/func-star/blog/issues/22)\n\n除此之外，mo-react-router 还融合了全局状态管理，用户可以将数据绑定在当前路径实例上，用户可以自由方便的通过路由来获取其他模块的数据。\n\n### 依赖\n\n- [@monajs/events](https://github.com/monajs/mona-events)\n\n### 安装\n\n```bash\n$ npm i --save @monajs/react-router\n```\n\n- [上手使用](#上手使用)\n- [如何实现页面间跳转](#如何实现页面间跳转)\n- [如何获取页面的信息](#如何获取页面的信息)\n- [如何监听路由变化](#如何监听路由变化)\n\n### 上手使用\n\n```js\nimport React, { Component } from 'react';\nimport { render } from 'react-dom';\nimport Router from '@monajs/react-router';\n\nimport DefaultLayout from 'views/layout/default'\nimport NoMatch from 'pages/noMatch'\nimport Home from 'pages/home'\n\nconst routerConf =  {\n\tindex: 'home',\n\temptyPage: 'test',\n\ttype: 'history',\n\trouteList: [\n\t\t{\n\t\t\tlayout: DefaultLayout,\n\t\t\troutes: {\n\t\t\t\t'home/:name/:count': Home\n\t\t\t}\n\t\t}, {\n\t\t\troutes: {\n\t\t\t\t'404': NoMatch\n\t\t\t}\n\t\t}\n\t]\n}\n\nrender(\u003cRouter config={routerConf} /\u003e, document.getElementById('appWrapper'));\n\n```\n\n#### config 属性介绍\n\n| 参数 | 说明 | 类型 | 默认值 |\n| --- | --- | --- | :-- |\n| index | 默认打开的路径 | String | null |\n| emptyPage | 未识别到路径时打开的路径 |String | '404' |\n| type | router 类型，提供 history 和 hash 两种选择 | String | 'hash' |\n| routeList | 路由配置列表 | Array | null |\n\n#### routeList 介绍\n- `layout` 指的是页面采用的布局，可以为空\n- `routes` 指的是页面的路径和页面实例的映射关系\n- 当路由类型为 history 时，可以通过 `/:`的姿势配置 url 传参数形式\n\n### 如何实现页面间跳转\n\n```js\nimport Router from '@monajs/react-router'\n\nconst Link = Router.link\n\n...\n\n\u003cLink activeClassName=\"active\" className=\"a\" to={{ path: 'home/name/321?age=25', state: { a: 1 } }}\u003etest\u003c/Link\u003e\n// \u003cLink activeClassName=\"active\" className=\"a\" to='home/name/321?age=25'\u003etest\u003c/Link\u003e\n```\n#### Link 组件 api\n\n| 参数 | 说明 | 类型 | 默认值 |\n| --- | --- | --- | :-- |\n| to | 跳转的目标页面信息 | String|Object | null |\n| activeClassName | 激活状态下的class | String | '' |\n| className | 附加className | String | '' |\n\n* 当路由类型为 history 时，可以通过设置 state 值来传递 history 的 state 属性\n\n#### api 跳转\n\n```js\nimport Router from '@monajs/react-router'\n\n...\n\nRouter.go ('404', {name: 'yangxi'}, 'title', {s: 'state'})\n```\n#### Router.go 方法参数\n`Router.go (path, data, title = '', state = {})`\n\n| 参数 | 说明 | 类型 | 默认值 |\n| --- | --- | --- | :-- |\n| path | 跳转路径 | String | '' |\n| data | 参数对象 | Object | {} |\n| title | 当路由类型为 history 时传递的 title 值 | String | '' |\n| state | 当路由类型为 history 时传递的 state 值 | Object | {} |\n\n\n### 如何获取页面的信息\n#### 获取本页面信息\n```js\nimport Router from '@monajs/react-router'\n\n...\n\nconsole.dir(Router.current)\n```\n#### 获取其他面信息\n```js\nimport Router from '@monajs/react-router'\n\n...\n\nconsole.dir(Router.routeInfo)\n```\n\n![Image text](./images/url.png)\n\n下面来介绍一下都包含哪些信息\n\n| 参数 | 说明 | 类型 | 默认值 |\n| --- | --- | --- | :-- |\n| ctrl | 绑定在 页面实例上的全局控制器，其他页面都可以通过 | Object | null |\n| layout | 当前页面采用的布局实例 | 类 | null |\n| page | 当前页面实例 | 类 | null |\n| params | 页面传递的参数 | Object | {} |\n| path | route 配置中的路径配置，包含参数 | String | '' |\n| state | 当路由类型为 history 时，页面传递的 state 参数 | Object | null |\n| url | url 实例 | Object | null |\n\n### 如何监听路由变化\n\n```js\nimport Router from '@monajs/react-router'\n...\n\nRouter.addEventListener('onChange', (res) =\u003e {\n\tconsole.log(res)\n})\n```\n\n## 联系我\n\u003e 微信：yx12032331\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonajs%2Fmona-react-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonajs%2Fmona-react-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonajs%2Fmona-react-router/lists"}