{"id":14384937,"url":"https://github.com/taion/use-named-routes","last_synced_at":"2025-04-14T16:34:15.876Z","repository":{"id":57388226,"uuid":"55572819","full_name":"taion/use-named-routes","owner":"taion","description":"[No Maintenance Intended] Drop-in named route support for React Router","archived":false,"fork":false,"pushed_at":"2016-11-28T18:29:35.000Z","size":18,"stargazers_count":106,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T10:18:43.908Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/taion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-06T03:22:52.000Z","updated_at":"2024-12-08T09:39:59.000Z","dependencies_parsed_at":"2022-08-31T14:34:44.403Z","dependency_job_id":null,"html_url":"https://github.com/taion/use-named-routes","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taion%2Fuse-named-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taion%2Fuse-named-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taion%2Fuse-named-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taion%2Fuse-named-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taion","download_url":"https://codeload.github.com/taion/use-named-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248916924,"owners_count":21182893,"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":[],"created_at":"2024-08-28T18:01:47.614Z","updated_at":"2025-04-14T16:34:15.837Z","avatar_url":"https://github.com/taion.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# No Maintenance Intended\n\n[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n# use-named-routes [![npm][npm-badge]][npm]\n\nDrop-in named route support for [React Router](https://github.com/reactjs/react-router).\n\n[![Discord][discord-badge]][discord]\n\n## Usage\n\nEnhance your history with `useNamedRoutes` and pass in your routes:\n\n```js\nimport createHistory from 'history/lib/createBrowserHistory';\nimport { Route, Router, useRouterHistory } from 'react-router';\nimport useNamedRoutes from 'use-named-routes';\n\n/* ... */\n\nconst routes = (\n  \u003cRoute path=\"/\"\u003e\n    \u003cRoute name=\"widgets\" path=\"widgets\" component={WidgetsPage}\u003e\n      \u003cRoute name=\"widget\" path=\":widgetId\" component={WidgetPage} /\u003e\n    \u003c/Route\u003e\n  \u003c/Route\u003e\n);\n\n// The order of history enhancers matters here.\nconst history = useNamedRoutes(useRouterHistory(createHistory))({ routes });\n\nReactDOM.render(\n  \u003cRouter history={history} routes={routes} /\u003e,\n  container\n);\n```\n\nYou can then use either route names or objects with `name` and optionally `params`:\n\n```js\nhistory.push('widgets');\nhistory.replace({ name: 'widgets', query: { color: 'blue' } });\n\nthis.context.router.push({ name: 'widget', params: { widgetId: 'foo' } });\n```\n\nThis also works with `\u003cLink\u003e`:\n\n```js\n\u003cLink to=\"widgets\"\u003e\n\n\u003cLink\n  to={{ name: 'widget', params: { widgetId: 'bar' } }}\n  activeClassName=\"active\"\n\u003e\n```\n\nNormal paths will also still work:\n\n```js\nhistory.push('/widgets/baz');\n\nthis.context.router.replace({ pathname: '/widgets', query: { color: 'red' } });\n\n\u003cLink to=\"/widgets/qux\"\u003e\n```\n\n## Guide\n\n### Installation\n\n```shell\n$ npm i -S react-router history@2 use-named-routes\n```\n\n### Route configuration\n\nuse-named-routes works with both JSX and plain route definitions. Define `name` on the route element or object to assign it a name.\n\nuse-named-routes ignores dynamic routes under `getChildRoutes` or `getIndexRoute`. You probably shouldn't be using those anyway – use `getComponent` or `getComponents` if you want code splitting.\n\n### Location descriptors\n\nLocation descriptor strings are treated as route names, except when the location descriptor begins with a `/`, in which case the location descriptor is passed to the base history as-is.\n\nLocation descriptor objects are treated as describing a named route if they have a `name` value. Any parameters in the path for the named route are populated from the `params` value. If no `name` value is present, the location descriptor is passed to the base history as-is.\n\nIn either case, if a name is present, the formatted pattern is passed to the base history as `pathname` on a location descriptor object. Other properties on the location descriptor are passed through as-is.\n\n\n[npm-badge]: https://img.shields.io/npm/v/use-named-routes.svg\n[npm]: https://www.npmjs.com/package/use-named-routes\n\n[discord-badge]: https://img.shields.io/badge/Discord-join%20chat%20%E2%86%92-738bd7.svg\n[discord]: https://discord.gg/0ZcbPKXt5bYaNQ46\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaion%2Fuse-named-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaion%2Fuse-named-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaion%2Fuse-named-routes/lists"}