{"id":20698842,"url":"https://github.com/rwson/mini-route","last_synced_at":"2026-04-18T20:02:00.657Z","repository":{"id":87105422,"uuid":"97668267","full_name":"rwson/mini-route","owner":"rwson","description":"a router plugin for web and nodejs","archived":false,"fork":false,"pushed_at":"2017-07-19T08:23:33.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T03:41:57.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/rwson.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-19T03:20:32.000Z","updated_at":"2017-07-19T07:20:39.000Z","dependencies_parsed_at":"2023-07-04T22:48:58.784Z","dependency_job_id":null,"html_url":"https://github.com/rwson/mini-route","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rwson/mini-route","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fmini-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fmini-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fmini-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fmini-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwson","download_url":"https://codeload.github.com/rwson/mini-route/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwson%2Fmini-route/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31982755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T17:30:12.329Z","status":"ssl_error","status_checked_at":"2026-04-18T17:29:59.069Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-17T00:27:07.443Z","updated_at":"2026-04-18T20:02:00.601Z","avatar_url":"https://github.com/rwson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mini-Route\n\n----\n\n支持浏览器和nodejs服务端(开发中)的路由组件\n\n\n\n### 客户端(browser/src/index.js)\n\n```html\n\u003cscript src=\"path/to/mini-route.js\"\u003e\u003c/script\u003e\n```\n\n```javascript\nwindow.onload = function() {\n  var router = MiniRoute(document.querySelector(\"#view\"));\n\trouter.config({\n\t\tpushState: true,\n\t\troutes: [\n\t\t\t{\n\t\t\t\tname: \"test111\",\n\t\t\t\turl: \"/test111\",\n\t\t\t\ttemplateUrl: \"/views/111.html\",\n\t\t\t\thandler: function() {\n\t\t\t\t\tconsole.log(\"I'm test111's handler\");\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"test222\",\n\t\t\t\turl: \"/test222\",\n\t\t\t\ttemplateUrl: \"/views/222.html\",\n\t\t\t\thandler: function() {\n\t\t\t\t\tconsole.log(\"I'm test222's handler\");\n\t\t\t\t\tdoc.querySelector(\".jump\").addEventListener(\"click\", function(e) {\n\t\t\t\t\t\trouter.go(\"test222333\", {\n\t\t\t\t\t\t\tname: \"fuck\",\n\t\t\t\t\t\t\tid: \"test\"\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"test222333\",\n\t\t\t\turl: \"/test222/:id/:name\",\n\t\t\t\ttemplateUrl: \"/views/222333.html\",\n\t\t\t\thandler: function(params) {\n\t\t\t\t\tconsole.log(params); //\t{ id: \"xxx\", name: \"yyy\" }\n\t\t\t\t\tconsole.log(\"I'm test2223333's handler\");\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t});\n\n\trouter.on(\"route:change:start\", function() {\n\t\tconsole.log(\"%c router change start callback\", \"color: yellow\");\n\t});\n\n\trouter.on(\"route:change:success\", function() {\n\t\tconsole.log(\"%c router change success callback\", \"color: green\");\n\t});\n\n\trouter.on(\"route:change:completed\", function() {\n\t\tconsole.log(\"%c router change completed callback\", \"color: blue\");\n\t});\n\n\trouter.on(\"route:change:failed\", function(e) {\n\t\tconsole.log(\"%c router change failed callback\", \"color: red\");\n\t\tconsole.log(e);\n\t});\n\n\trouter.start();\n}\n```\n\n#### API\n\n| 方法名    | 意义                | 参数类型                | 是否必须 |\n| ------ | ----------------- | ------------------- | ---- |\n| config | 路由相关配置            | Object(详见注释1)       | 是    |\n| on     | 订阅路由切换时相关声明周期     | String [, Function] | 是    |\n| start  | 启动路由              | 空                   | 否    |\n| go     | 跳转到某个路由, 可以加上具体参数 | name [, Object]     | 是    |\n\n#### 注释1(config方法相关参数)\n\n| 参数名       | 意义                              | 取值类型                   | 默认值   |\n| --------- | ------------------------------- | ---------------------- | ----- |\n| pushState | 是否启用HTML5的pushState, false为hash | Boolean                | false |\n| routes    | 路由配置项                           | Array.\u003cObject\u003e/ Object | null  |\n\n-   routes为数组类型时，必须保证为如下结构\n\n```javascript\n[\n  {\n  \tname: String, Required,\n  \turl: String, Required,\n  \ttemplateUrl: String, Required,\n  \thandler: Function, Optional\n  }\n]\n```\n\n当url配置为带参数的rest风格时，handler的第一个参数即为当前页面路由的参数和值的键值对\n\n-   router为对象类型时，必须保证为如下结构 \n\n```javascript\n{\n  name: {\n    url: String, Required,\n    templateUrl: String, Required,\n    handler: Function, Optional\n  }\n}\n```\n\n当url配置为带参数的rest风格时，handler的第一个参数即为当前页面路由的参数和值的键值对\n\n#### 路由切换生命周期\n\n| 名称                     | 意义                              |\n| ---------------------- | ------------------------------- |\n| route:change:start     | 路由切换开始，在发起获取模板请求之前触发            |\n| route:change:success   | 路由切换成功，在获取模板返回成功后触发，模板未被插入到DOM中 |\n| route:change:failed    | 路由切换失败，发生异常时触发，并且有相关异常参数        |\n| route:change:completed | 路由切换完成，模板已被插入到DOM中              |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Fmini-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwson%2Fmini-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwson%2Fmini-route/lists"}