{"id":15680995,"url":"https://github.com/blakeembrey/react-location","last_synced_at":"2025-05-07T10:35:25.943Z","repository":{"id":33660540,"uuid":"158987357","full_name":"blakeembrey/react-location","owner":"blakeembrey","description":"Light-weight and universal react routing","archived":false,"fork":false,"pushed_at":"2022-06-22T22:09:36.000Z","size":552,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:35:03.602Z","etag":null,"topics":["hash-router","history-router","react","react-context","react-location","react-router","router"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blakeembrey.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":"2018-11-25T01:20:16.000Z","updated_at":"2025-04-12T07:29:35.000Z","dependencies_parsed_at":"2022-07-25T19:02:21.629Z","dependency_job_id":null,"html_url":"https://github.com/blakeembrey/react-location","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Freact-location","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Freact-location/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Freact-location/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Freact-location/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blakeembrey","download_url":"https://codeload.github.com/blakeembrey/react-location/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252860398,"owners_count":21815510,"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":["hash-router","history-router","react","react-context","react-location","react-router","router"],"created_at":"2024-10-03T16:47:57.191Z","updated_at":"2025-05-07T10:35:25.918Z","avatar_url":"https://github.com/blakeembrey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Location\n\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][downloads-image]][downloads-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\n\u003e Light-weight and universal React.js routing.\n\n## Installation\n\n```\nnpm install @blakeembrey/react-location --save\n```\n\n## Usage\n\n**React Location** exports a React.js `Context` to control routing. The default router is `SimpleLocation`, useful for testing or server-side rendering.\n\n```js\nimport { Link, useURL } from \"@blakeembrey/react-location\";\n\nconst App = () =\u003e {\n  const url = useURL();\n\n  return (\n    \u003cdiv\u003e\n      \u003cnav\u003e\n        \u003cLink to=\"/\"\u003eHome\u003c/Link\u003e\n        \u003cLink to=\"/about\"\u003eAbout\u003c/Link\u003e\n      \u003c/nav\u003e\n\n      {url.pathname === \"/\" \u0026\u0026 \u003cdiv\u003eHome\u003c/div\u003e}\n      {url.pathname === \"/about\" \u0026\u0026 \u003cdiv\u003eAbout\u003c/div\u003e}\n    \u003c/div\u003e\n  );\n};\n```\n\n**Location Properties:**\n\n- `url` Get the locations current [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL)\n- `push(location: string)` Push the user to a new URL (e.g. `\u003cLink /\u003e` or dynamic redirects)\n- `format(location: string)` Format the URL for `\u003cLink /\u003e`\n- `onChange(fn: () =\u003e void)` Notify `fn` on URL change (returns an `unsubscribe` function)\n\n**Tip:** For a simpler routing experience, combine with [`@blakeembrey/react-route`](https://github.com/blakeembrey/react-route).\n\n```js\nimport { Route } from \"@blakeembrey/react-route\";\n\nexport default () =\u003e (\n  \u003cdiv\u003e\n    \u003cRoute path=\"/\"\u003e{() =\u003e \u003cdiv\u003eHome\u003c/div\u003e}\u003c/Route\u003e\n    \u003cRoute path=\"/page/:id\"\u003e{([id]) =\u003e \u003cPage id={id} /\u003e}\u003c/Route\u003e\n  \u003c/div\u003e\n);\n```\n\n### [Hash Location](examples/hash/app.js)\n\n```js\nimport { Context, HashLocation } from \"@blakeembrey/react-location\";\n\n\u003cContext.Provider value={new HashLocation()}\u003e\n  \u003cApp /\u003e\n\u003c/Context.Provider\u003e;\n```\n\n### [History Location](examples/history/app.js)\n\n```js\nimport { Context, HistoryLocation } from \"@blakeembrey/react-location\";\n\n\u003cContext.Provider value={new HistoryLocation()}\u003e\n  \u003cApp /\u003e\n\u003c/Context.Provider\u003e;\n```\n\n### [Simple Location](examples/simple/app.js)\n\nUseful for testing React.js applications or server-side rendering.\n\n```js\nimport { Context, SimpleLocation } from '@blakeembrey/react-location'\n\n// E.g. `req.url` from a node.js HTTP server.\nconst location = new SimpleLocation(new URL(`http://example.com${req.url}`))\n\n\u003cContext.Provider value={location}\u003e\n  \u003cApp /\u003e\n\u003c/Context.Provider\u003e\n```\n\n## TypeScript\n\nThis project uses [TypeScript](https://github.com/Microsoft/TypeScript) and publishes definitions on NPM.\n\n## License\n\nApache 2.0\n\n[npm-image]: https://img.shields.io/npm/v/@blakeembrey/react-location.svg?style=flat\n[npm-url]: https://npmjs.org/package/@blakeembrey/react-location\n[downloads-image]: https://img.shields.io/npm/dm/@blakeembrey/react-location.svg?style=flat\n[downloads-url]: https://npmjs.org/package/@blakeembrey/react-location\n[travis-image]: https://img.shields.io/travis/blakeembrey/react-location.svg?style=flat\n[travis-url]: https://travis-ci.org/blakeembrey/react-location\n[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/react-location.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/blakeembrey/react-location?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Freact-location","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakeembrey%2Freact-location","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Freact-location/lists"}