{"id":16181710,"url":"https://github.com/ericclemmons/react-router-server-location","last_synced_at":"2025-03-19T01:31:15.219Z","repository":{"id":36120605,"uuid":"40423281","full_name":"ericclemmons/react-router-server-location","owner":"ericclemmons","description":"A React Router Location for universal apps.","archived":false,"fork":false,"pushed_at":"2015-08-24T04:59:38.000Z","size":200,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T19:03:21.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"LambdaSchool/responsive-web-design-I","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericclemmons.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":"2015-08-09T02:52:00.000Z","updated_at":"2022-04-21T05:45:40.000Z","dependencies_parsed_at":"2022-09-12T06:51:02.895Z","dependency_job_id":null,"html_url":"https://github.com/ericclemmons/react-router-server-location","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Freact-router-server-location","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Freact-router-server-location/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Freact-router-server-location/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Freact-router-server-location/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericclemmons","download_url":"https://codeload.github.com/ericclemmons/react-router-server-location/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960361,"owners_count":20375102,"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-10-10T06:26:50.454Z","updated_at":"2025-03-19T01:31:14.970Z","avatar_url":"https://github.com/ericclemmons.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Router `ServerLocation` ![https://img.shields.io/npm/v/react-router-server-location.svg](https://img.shields.io/npm/v/react-router-server-location.svg?style=flat-square)\n\n\u003e A [React Router][1] Location for universal apps.\n\n[![](https://img.shields.io/github/issues-raw/ericclemmons/react-router-server-location.svg?style=flat-square)](https://github.com/ericclemmons/react-router-server-location/issues)\n[![](https://img.shields.io/travis/ericclemmons/react-router-server-location/master.svg?style=flat-square)](https://travis-ci.org/ericclemmons/react-router-server-location)\n[![](https://img.shields.io/david/ericclemmons/react-router-server-location.svg?style=flat-square)](https://david-dm.org/ericclemmons/react-router-server-location#info=dependencies)\n\n- - -\n\n### What does `ServerLocation` Do?\n\n- Normalizes \u0026 exposes server-side request data so that React Router\n  (and your components) can respond to all HTTP methods (e.g. `GET`, `POST`).\n\n- Redirects server-side requests when the router transitions to another URL.\n\n- Correctly supports complex, deep query strings (e.g. `?foo[bar][baz][bing]=...`)\n\n- Allows the use of `\u003cRedirect\u003e` routes on the server as well as the client.\n\n- Works with both [Express][3] \u0026 [Hapi][4].\n\n\n### Why `ServiceLocation`?\n\nBy default, [React Router][1] uses [StaticLocation](http://rackt.github.io/react-router/#StaticLocation)\non the server which does not support transitions.  Also, in my experience,\nthe `onAbort` handler has not been a reliable means of handling this behavior.\n\nPlus, `ServerLocation` allows your app components to take advantage of:\n\n- Redirect server-side requests via `router.transitionTo`.\n- The HTTP method via `query._method` (e.g. `GET`, `POST`).\n- `POST` params are available on the `query` like normal `GET` query params.\n- Access to HTTP headers via `query._headers`\n  (which is useful for pivoting off of `X-Requested-With`)\n\n\n### Installation\n\n```shell\n$ npm install --save react-router-server-location\n```\n\n\n### Usage\n\nFirst, include `ServerLocation` as a dependency:\n\n```js\nimport ServerLocation from \"react-router-server-location\";\n```\n\nNext, create an instance using your server's request \u0026 response objects:\n\n```js\n// Express\nconst location = new ServerLocation({ req, res });\n\n// or Hapi\nconst location = new ServerLocation({ request, reply });\n```\n\nFinally, use [React Router][1] as normal:\n\n```js\nRouter.create({ location, routes }).run((Root) =\u003e {\n  React.renderToString(\u003cRoot /\u003e);\n});\n```\n\nNow, calls to `router.transitionTo` will redirect as expected on the server,\nand `POST` requests to your server-side React application can be supported!\n\nIf you'd like to handle redirects manually, you can instead pass a callback:\n\n```js\nconst location = new ServerLocation({ req }, function(path) {\n  // Maybe save data to the session...\n  req.session.redirected = true;\n  res.redirect(path);\n});\n```\n\n_The `res` or `reply` objects aren't necessary since we're providing our own\ncallback._\n\n\n## Authors\n\n- [Eric Clemmons](mailto:eric@smarterspam.com\u003e) ([@ericclemmons][twitter])\n\n\n## [License][license]\n\n\n## Collaboration\n\nIf you have questions or issues, please [open an issue][issue]!\n\n\n[1]: http://rackt.github.io/react-router/\n[2]: https://github.com/ericclemmons/react-resolver\n[3]: http://expressjs.com/\n[4]: http://hapijs.com/\n[issue]: https://github.com/ericclemmons/react-router-server-location/issues/new\n[license]: https://github.com/ericclemmons/react-router-server-location/blob/master/LICENSE\n[twitter]: https://twitter.com/ericclemmons/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Freact-router-server-location","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericclemmons%2Freact-router-server-location","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Freact-router-server-location/lists"}