{"id":19750505,"url":"https://github.com/57code/mini-router","last_synced_at":"2026-04-15T11:34:50.146Z","repository":{"id":97536891,"uuid":"473026455","full_name":"57code/mini-router","owner":"57code","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-31T14:15:41.000Z","size":185,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T08:31:20.286Z","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/57code.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":"2022-03-23T03:43:19.000Z","updated_at":"2022-03-31T14:05:39.000Z","dependencies_parsed_at":"2023-03-06T09:15:53.864Z","dependency_job_id":null,"html_url":"https://github.com/57code/mini-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/57code/mini-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/57code%2Fmini-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/57code%2Fmini-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/57code%2Fmini-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/57code%2Fmini-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/57code","download_url":"https://codeload.github.com/57code/mini-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/57code%2Fmini-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31839647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T11:29:19.690Z","status":"ssl_error","status_checked_at":"2026-04-15T11:29:19.171Z","response_time":63,"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-12T02:35:39.988Z","updated_at":"2026-04-15T11:34:50.127Z","avatar_url":"https://github.com/57code.png","language":"JavaScript","readme":"# mini-vue-router\n小羊们好，这是村长私教课`Vue3全家桶原理及手写`中产出的代码，想要深入学习Vue全家桶原理的小伙伴可以加我vx：`kkb_cunzhang`。\n\n![profile](./src/assets/profile.png)\n\n## 分析\n\n以上是`VueRouter`文档上的介绍，我们想要实现自己的`mini-router`，先来看看它都完成了什么任务：\n\n- 将我们的组件映射到路由上\n- 让 VueRouter 知道在哪里渲染它们\n\n\n## 体验\n\n所以我们的代码会像下面这样写：\n\n- router-link负责路由跳转\n- router-view告诉知道在哪渲染组件\n\n```Vue\n  \u003c!-- App.vue --\u003e\n  \u003cp\u003e\n    \u003c!--使用 router-link 组件进行导航 --\u003e\n    \u003c!--`\u003crouter-link\u003e` 将呈现一个带有正确 `href` 属性的 `\u003ca\u003e` 标签--\u003e\n    \u003crouter-link to=\"/\"\u003eGo to Home\u003c/router-link\u003e |\n    \u003crouter-link to=\"/about\"\u003eGo to About\u003c/router-link\u003e\n  \u003c/p\u003e\n  \u003c!-- 路由出口 --\u003e\n  \u003c!-- 路由匹配到的组件将渲染在这里 --\u003e\n  \u003crouter-view\u003e\u003c/router-view\u003e\n```\n\n\n\n还有个问题是上面的url如何映射到组件，于是有了创建路由时的映射表：\n\n```Vue\n// router/index.js\n// 1. 引入组件\nimport Home from \"../views/home.vue\";\nimport About from \"../views/about.vue\";\n\n// 2. 定义一些路由：每个路由都需要映射到一个组件。\nconst routes = [\n  { path: \"/\", component: Home },\n  { path: \"/about\", component: About },\n];\n\n// 3. 创建路由实例并传递 `routes` 配置\nconst router = createRouter({\n  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。\n  history: createWebHashHistory(),\n  routes, // `routes: routes` 的缩写\n});\n\nexport default router;\n\n```\n\n\n最后是如何引入到vue中：\n\n```Vue\n// main.js\nimport router from './router'\n\ncreateApp(App).use(router).mount('#app')\n\n```\n\n## 思路\n\n经过上面分析，我们大致有了思路：\n\n- 定义一个Vue插件作为载体\n- 实现两个组件router-view和router-link\n- 实现创建路由实例的createRouter()\n- 实现创建执行模式的createWebHashHistory()\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F57code%2Fmini-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F57code%2Fmini-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F57code%2Fmini-router/lists"}