{"id":19936382,"url":"https://github.com/jedirandy/redux-url","last_synced_at":"2025-05-03T13:30:57.125Z","repository":{"id":19041490,"uuid":"82862880","full_name":"jedirandy/redux-url","owner":"jedirandy","description":":monorail: A redux middleware for synchronizing the url with your redux store's state.","archived":false,"fork":false,"pushed_at":"2023-01-06T01:57:06.000Z","size":3401,"stargazers_count":7,"open_issues_count":28,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T19:44:17.435Z","etag":null,"topics":["javascript","javascript-library","react","redux","redux-middleware","redux-url","router"],"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/jedirandy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-22T23:27:51.000Z","updated_at":"2021-10-30T22:08:29.000Z","dependencies_parsed_at":"2023-01-14T00:30:14.075Z","dependency_job_id":null,"html_url":"https://github.com/jedirandy/redux-url","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedirandy%2Fredux-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedirandy%2Fredux-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedirandy%2Fredux-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedirandy%2Fredux-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedirandy","download_url":"https://codeload.github.com/jedirandy/redux-url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224362416,"owners_count":17298702,"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":["javascript","javascript-library","react","redux","redux-middleware","redux-url","router"],"created_at":"2024-11-12T23:25:47.889Z","updated_at":"2024-11-12T23:25:48.525Z","avatar_url":"https://github.com/jedirandy.png","language":"JavaScript","funding_links":[],"categories":["Marks"],"sub_categories":["[React - A JavaScript library for building user interfaces](http://facebook.github.io/react)"],"readme":"# redux-url\n\n[![Build Status](https://travis-ci.org/jedirandy/redux-url.svg?branch=master)](https://travis-ci.org/jedirandy/redux-url)\n[![npm module](https://badge.fury.io/js/redux-url.svg)](https://www.npmjs.org/package/redux-url)\n\nA redux middleware for synchronizing the url with your redux store's state. It provides a set of action creators for changing the url, and if the url matches a user-defined route, an action will be dispatched with some metadata of the url such as parameters and query.\n\nIt works with redux 3.x, 4.x\n\n## Install\n\n```\nnpm install --save redux-url\n```\n\n## Usage\n\n```javascript\nimport { createBrowserHistory as createHistory } from 'history'; // choose a history implementation\nimport { createStore, applyMiddleware } from 'redux';\nimport { createRouter, navigate } from 'redux-url';\n\nconst routes = {\n    '/': 'HOME', // when url is matched, will dispatch an action of type 'HOME', the payload contains matched params and query\n    '/todos/:id': ({ id }, query) =\u003e ({ type: 'CHANGE_TODO', payload: id, query }), // you can also pass a function to transform the action, the matched params, query and the original path will be passed in\n    '*': 'NOT_FOUND'\n};\n\nconst router = createRouter(routes, createHistory());\nconst store = createStore(\n    reducer,\n    applyMiddleware(router)\n);\n\nrouter.sync(); // In order to restore the state from the URL when refreshed\n\nstore.dispatch(navigate('/todos/123')); // navigate to '/todos/123'\n\n```\n\n## API\n\n* `createRouter(routes, history)`:\n\n  creates the middleware\n  - arguments\n    * routes (*object*) : The URL patterns to be mapped, where values can be either of the following:\n      * *string*:\n\n        when the URL matches the route, an action will be dispatched of which the type is the given string, and the payload has the following shape:\n\n      ```javascript\n        {\n          type: string,\n          payload: {\n            params: Object,\n            query: Object,\n            path: string\n          }\n        }\n      ```\n\n      * *function*: (object, object, string) =\u003e Action\n\n        a function that takes the matched `params`, `query` and the original `path`, returns an action\n\n    * history: the history object created from lib [`history`](https://github.com/ReactTraining/history),\n    such as `createBrowserHistory`\n\n  - returns\n\n    the middleware which provides the following methods:\n\n    * `sync()`:\n\n    synchronize the current url with the state, this is useful for handling the situation when the page is refreshed\n\n* `navigate(path: string, replace: boolean = false)`:\n\n  creates an action for navigating to the path, `replace` indicates whether it should modify the current history entry rather than push a new one\n\n* `push(path: string)`:\n\n  a shorthand of navigate(path, false)\n\n* `replace(path, string)`:\n\n  a shorthand of navigate(path, true)\n\n* `goBack()`:\n\n  creates an action for going back\n\n* `goForward()`:\n\n  creates an action for going forward\n\n* `go(n: number)`:\n\n  creates an action for going n (can be negative) steps\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedirandy%2Fredux-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedirandy%2Fredux-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedirandy%2Fredux-url/lists"}