{"id":13400430,"url":"https://github.com/kriasoft/universal-router","last_synced_at":"2025-05-14T01:10:46.507Z","repository":{"id":33565997,"uuid":"37212254","full_name":"kriasoft/universal-router","owner":"kriasoft","description":"A simple middleware-style router for isomorphic JavaScript web apps","archived":false,"fork":false,"pushed_at":"2025-05-05T09:49:16.000Z","size":1352,"stargazers_count":1732,"open_issues_count":32,"forks_count":106,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-05-12T09:23:29.274Z","etag":null,"topics":["react","reactjs","router","routes","routing","server-side-rendering","single-page-app","spa","ssr","vuejs"],"latest_commit_sha":null,"homepage":"https://www.kriasoft.com/universal-router/","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/kriasoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"universal-router"}},"created_at":"2015-06-10T17:37:51.000Z","updated_at":"2025-05-05T09:35:42.000Z","dependencies_parsed_at":"2025-04-26T21:01:56.119Z","dependency_job_id":"9375f472-1ce1-4952-9481-619ddcd496ea","html_url":"https://github.com/kriasoft/universal-router","commit_stats":{"total_commits":207,"total_committers":23,"mean_commits":9.0,"dds":0.5217391304347826,"last_synced_commit":"7820c62d89e95c941d7800eacf2df3ee22c2103d"},"previous_names":["kriasoft/react-routing"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Funiversal-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Funiversal-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Funiversal-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriasoft%2Funiversal-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kriasoft","download_url":"https://codeload.github.com/kriasoft/universal-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253737679,"owners_count":21956073,"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","reactjs","router","routes","routing","server-side-rendering","single-page-app","spa","ssr","vuejs"],"created_at":"2024-07-30T19:00:51.947Z","updated_at":"2025-05-14T01:10:46.455Z","avatar_url":"https://github.com/kriasoft.png","language":"TypeScript","funding_links":["https://opencollective.com/universal-router","https://opencollective.com/universal-router/backer/0/website","https://opencollective.com/universal-router/backer/1/website","https://opencollective.com/universal-router/backer/2/website","https://opencollective.com/universal-router/backer/3/website","https://opencollective.com/universal-router/backer/4/website","https://opencollective.com/universal-router/backer/5/website","https://opencollective.com/universal-router/backer/6/website","https://opencollective.com/universal-router/backer/7/website","https://opencollective.com/universal-router/backer/8/website","https://opencollective.com/universal-router/backer/9/website"],"categories":["Routing","Code Design","Uncategorized","JavaScript","Previous work I liked and guided me","Utilities","TypeScript","react","vuejs","routers (except r-r)","目录","React [🔝](#readme)"],"sub_categories":["Router","Uncategorized","Animation","\u003ca id=\"router\"\u003e路由\u003c/a\u003e"],"readme":"# Universal Router\n\n[![NPM version](https://img.shields.io/npm/v/universal-router.svg)](https://www.npmjs.com/package/universal-router)\n[![NPM downloads](https://img.shields.io/npm/dw/universal-router.svg)](https://www.npmjs.com/package/universal-router)\n[![Library Size](https://img.shields.io/bundlephobia/minzip/universal-router.svg)](https://bundlephobia.com/result?p=universal-router)\n[![Online Chat](https://badges.gitter.im/kriasoft/universal-router.svg)](https://gitter.im/kriasoft/universal-router)\n\n\u003ca href=\"https://www.kriasoft.com/universal-router/\" target=\"_blank\"\u003e\n  \u003cimg width=\"64\" height=\"64\" align=\"right\" alt=\"Visit Universal Router Website\"\n  src=\"https://rawgit.com/kriasoft/universal-router/master/logo.svg\" /\u003e\n\u003c/a\u003e\n\nA simple middleware-style router that can be used in both client-side and server-side applications.\n\nVisit **[Quickstart Guide](http://slides.com/koistya/universal-router)** (slides) \u0026nbsp;|\u0026nbsp;\nJoin **[#universal-router](https://gitter.im/kriasoft/universal-router)** on Gitter to stay up to date\n\n## Features\n\n- It has [simple code](https://github.com/kriasoft/universal-router/blob/master/src/UniversalRouter.ts)\n  with only single [path-to-regexp](https://github.com/pillarjs/path-to-regexp) dependency.\n- It can be used with any JavaScript framework such as\n  [React](https://reactjs.org/), [Vue](https://vuejs.org/), [Hyperapp](https://hyperapp.dev/) etc.\n- It uses the same middleware approach used in [Express](http://expressjs.com/) and [Koa](http://koajs.com/),\n  making it easy to learn.\n- It supports both [imperative](https://en.wikipedia.org/wiki/Imperative_programming) and\n  [declarative](https://en.wikipedia.org/wiki/Declarative_programming) routing style.\n- Routes are plain JavaScript\n  [objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer)\n  with which you can interact as you like.\n\n## What users say about Universal Router\n\n\u003e Just switched a project over to universal-router.\n\u003e Love that the whole thing is a few hundred lines of flexible, easy-to-read code.\n\u003e\n\u003e -- [Tweet](https://twitter.com/wincent/status/862115805378494464) by **Greg Hurrell** from Facebook\n\n\u003e It does a great job at trying to be _universal_ — it's not tied to any framework,\n\u003e it can be run on both server and client, and it's not even tied to history.\n\u003e It's a great library which does one thing: routing.\n\u003e\n\u003e -- [Comment on Reddit](https://www.reddit.com/r/reactjs/comments/5xhw3o#form-t1_dejkw4p367)\n\u003e by **@everdimension**\n\n## Installation\n\nUsing [npm](https://www.npmjs.com/package/universal-router):\n\n```bash\nnpm install universal-router --save\n```\n\nOr using a [CDN](https://en.wikipedia.org/wiki/Content_delivery_network) like\n[unpkg.com](https://unpkg.com/universal-router/universal-router.min.js) or\n[jsDelivr](https://cdn.jsdelivr.net/npm/universal-router/universal-router.min.js)\nwith the following script tag:\n\n```html\n\u003cscript src=\"https://unpkg.com/universal-router/universal-router.min.js\"\u003e\u003c/script\u003e\n```\n\nYou can find the library in `window.UniversalRouter`.\n\n## How does it look like?\n\n```js\nimport UniversalRouter from 'universal-router'\n\nconst routes = [\n  {\n    path: '', // optional\n    action: () =\u003e `\u003ch1\u003eHome\u003c/h1\u003e`\n  },\n  {\n    path: '/posts',\n    action: () =\u003e console.log('checking child routes for /posts'),\n    children: [\n      {\n        path: '', // optional, matches both \"/posts\" and \"/posts/\"\n        action: () =\u003e `\u003ch1\u003ePosts\u003c/h1\u003e`\n      },\n      {\n        path: '/:id',\n        action: (context) =\u003e `\u003ch1\u003ePost #${context.params.id}\u003c/h1\u003e`\n      }\n    ]\n  }\n]\n\nconst router = new UniversalRouter(routes)\n\nrouter.resolve('/posts').then(html =\u003e {\n  document.body.innerHTML = html // renders: \u003ch1\u003ePosts\u003c/h1\u003e\n})\n```\n\nPlay with an example on [JSFiddle](https://jsfiddle.net/frenzzy/b0w9mjck/102/),\n[CodePen](https://codepen.io/frenzzy/pen/aWLKpb?editors=0010),\n[JS Bin](https://jsbin.com/kaluden/3/edit?js,output) in your browser or try\n[RunKit](https://runkit.com/frenzzy/universal-router-demo) node.js playground.\n\n## Documentation\n\n- [Getting Started](https://github.com/kriasoft/universal-router/blob/master/docs/getting-started.md)\n- [Universal Router API](https://github.com/kriasoft/universal-router/blob/master/docs/api.md)\n\n## Books and Tutorials\n\n- 🎓 **[ES6 Training Course](https://es6.io/friend/konstantin)**\n  by [Wes Bos](https://twitter.com/wesbos)\n- 📗 **[You Don't Know JS: ES6 \u0026 Beyond](http://amzn.to/2bFss85)**\n  by [Kyle Simpson](https://github.com/getify) (Dec, 2015)\n- 📄 **[You might not need React Router](https://medium.freecodecamp.org/38673620f3d)**\n  by [Konstantin Tarkus](https://twitter.com/koistya)\n- 📄 **[An Introduction to the Redux-First Routing Model](https://medium.freecodecamp.org/98926ebf53cb)**\n  by [Michael Sargent](https://twitter.com/michaelksarge)\n- 📄 **[Getting Started with Relay Modern for Building Isomorphic Web Apps](https://hackernoon.com/ae049e4e23c1)**\n  by [Konstantin Tarkus](https://twitter.com/koistya)\n\n## Browser Support\n\nWe support all ES5-compliant browsers, including Internet Explorer 9 and above,\nbut depending on your target browsers you may need to include\n[polyfills](\u003chttps://en.wikipedia.org/wiki/Polyfill_(programming)\u003e) for\n[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map),\n[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) and\n[`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)\nbefore any other code.\n\nFor compatibility with older browsers you may also need to include polyfills for\n[`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)\nand [`Object.create`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create).\n\n## Contributing\n\nAnyone and everyone is welcome to\n[contribute](https://github.com/kriasoft/universal-router/blob/master/.github/CONTRIBUTING.md) to this project.\nThe best way to start is by checking our [open issues](https://github.com/kriasoft/universal-router/issues),\nsubmit a [bug report](https://github.com/kriasoft/universal-router/blob/master/.github/CONTRIBUTING.md#bugs) or\n[feature request](https://github.com/kriasoft/universal-router/blob/master/.github/CONTRIBUTING.md#features),\nparticipate in discussions, upvote or downvote the issues you like or dislike, send [pull\nrequests](https://github.com/kriasoft/universal-router/blob/master/.github/CONTRIBUTING.md#pull-requests).\n\n## Support\n\n- [#universal-router](https://gitter.im/kriasoft/universal-router) on Gitter —\n  Watch announcements, share ideas and feedback.\n- [GitHub Issues](https://github.com/kriasoft/universal-router/issues) —\n  Check open issues, send feature requests.\n- [@koistya](https://twitter.com/koistya) on [Codementor](https://www.codementor.io/koistya),\n  [HackHands](https://hackhands.com/koistya/)\n  or [Skype](https://hatscripts.com/addskype?koistya) — Private consulting.\n\n## Related Projects\n\n- [React Starter Kit](https://github.com/kriasoft/react-starter-kit) —\n  Boilerplate and tooling for building isomorphic web apps with React and Relay.\n- [Node.js API Starter Kit](https://github.com/kriasoft/nodejs-api-starter) —\n  Boilerplate and tooling for building data APIs with Docker, Node.js and GraphQL.\n- [ASP.NET Core Starter Kit](https://github.com/kriasoft/aspnet-starter-kit) —\n  Cross-platform single-page application boilerplate (ASP.NET Core, React, Redux).\n- [Babel Starter Kit](https://github.com/kriasoft/babel-starter-kit) —\n  Boilerplate for authoring JavaScript/React.js libraries.\n- [React App SDK](https://github.com/kriasoft/react-app) —\n  Create React apps with just a single dev dependency and zero configuration.\n- [React Static Boilerplate](https://github.com/kriasoft/react-static-boilerplate) —\n  Single-page application (SPA) starter kit (React, Redux, Webpack, Firebase).\n- [History](https://github.com/ReactTraining/history) —\n  HTML5 History API wrapper library that handle navigation in single-page apps.\n- [Redux-First Routing](https://github.com/mksarge/redux-first-routing) —\n  A minimal, framework-agnostic API for accomplishing Redux-first routing.\n\n## Sponsors\n\nBecome a sponsor and get your logo on our README on Github with a link to your site.\n[[Become a sponsor](https://opencollective.com/universal-router#sponsor)]\n\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/0/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/0/avatar.svg\" height=\"64\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/1/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/1/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/2/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/2/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/3/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/3/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/4/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/4/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/5/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/5/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/6/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/6/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/7/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/7/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/8/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/8/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/sponsor/9/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/sponsor/9/avatar.svg\"\u003e\n\u003c/a\u003e\n\n## Backers\n\nSupport us with a monthly donation and help us continue our activities.\n[[Become a backer](https://opencollective.com/universal-router#backer)]\n\n\u003ca href=\"https://opencollective.com/universal-router/backer/0/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/0/avatar.svg\" height=\"64\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/1/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/1/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/2/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/2/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/3/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/3/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/4/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/4/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/5/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/5/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/6/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/6/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/7/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/7/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/8/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/8/avatar.svg\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/universal-router/backer/9/website\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://opencollective.com/universal-router/backer/9/avatar.svg\"\u003e\n\u003c/a\u003e\n\n## License\n\nCopyright © 2015-present Kriasoft.\nThis source code is licensed under the MIT license found in the\n[LICENSE.txt](https://github.com/kriasoft/universal-router/blob/master/LICENSE.txt) file.\nThe documentation to the project is licensed under the\n[CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/) license.\n\n---\n\nMade with ♥ by\n[Konstantin Tarkus](https://github.com/koistya)\n([@koistya](https://twitter.com/koistya), [blog](https://medium.com/@tarkus)),\n[Vladimir Kutepov](https://github.com/frenzzy)\nand [contributors](https://github.com/kriasoft/universal-router/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriasoft%2Funiversal-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkriasoft%2Funiversal-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriasoft%2Funiversal-router/lists"}