{"id":16906320,"url":"https://github.com/chrisru/es6-router","last_synced_at":"2026-03-14T05:33:01.985Z","repository":{"id":57227229,"uuid":"95317636","full_name":"ChrisRu/es6-router","owner":"ChrisRu","description":"🌐 Simple client side router built in ES6","archived":false,"fork":false,"pushed_at":"2021-01-02T13:42:29.000Z","size":65,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T22:09:36.868Z","etag":null,"topics":["es6","es6-router","es6-routing","jest","router","routing"],"latest_commit_sha":null,"homepage":"https://npm.im/es6-router","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/ChrisRu.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-06-24T19:13:01.000Z","updated_at":"2023-01-25T01:02:31.000Z","dependencies_parsed_at":"2022-08-25T14:41:07.789Z","dependency_job_id":null,"html_url":"https://github.com/ChrisRu/es6-router","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/ChrisRu%2Fes6-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisRu%2Fes6-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisRu%2Fes6-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChrisRu%2Fes6-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChrisRu","download_url":"https://codeload.github.com/ChrisRu/es6-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245140719,"owners_count":20567432,"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":["es6","es6-router","es6-routing","jest","router","routing"],"created_at":"2024-10-13T18:42:13.324Z","updated_at":"2026-03-14T05:33:01.922Z","avatar_url":"https://github.com/ChrisRu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ES6 Router\n\n[![Licence](https://img.shields.io/github/license/ChrisRu/es6-router.svg)](https://github.com/ChrisRu/es6-router/blob/master/LICENSE.md)\n[![Tests](https://circleci.com/gh/circleci/mongofinil.svg?\u0026style=shield\u0026circle-token=b14acf911433d315298235b0c2fbf7b2670a92a8)](https://circleci.com/gh/ChrisRu/es6-router)\n\nA simple client side router built in **ES6** *with 0 dependencies* and TypeScript definitions.\n\n## Usage\n\n```js\nconst router = new Router({ ... })\n  .add(() =\u003e {\n    // getPage('/');\n  })\n  .add(/about/, () =\u003e {\n    // getPage('about');\n  })\n  .add('contact', () =\u003e {\n    // getPage('contact');\n  });\n\nrouter.remove('contact');\nrouter.navigate('about');\n```\n\n## API\n\n#### constuctor\n\n| Param                  | Type                         | Description                            |\n| ---------------------- | ---------------------------- | -------------------------------------- |\n| options                | \u003ccode\u003eObject\u003c/code\u003e          | Options object                         |\n| options.debug          | \u003ccode\u003eboolean\u003c/code\u003e (false) | Enable debugging                       |\n| options.context        | \u003ccode\u003eObject\u003c/code\u003e (window) | Context to add event listener to       |\n| options.startListening | \u003ccode\u003eboolean\u003c/code\u003e (true)  | Start listening when router is created |\n\n\u003chr\u003e\n\n#### currentRoute ⇒ \u003ccode\u003estring\u003c/code\u003e\n\nName of the current route\n\n_Returns_: \u003ccode\u003estring\u003c/code\u003e - Current route\n\n\u003chr\u003e\n\n#### add(route, handler) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nAdd a new route\n\n| Param   | Type                                       | Description                          |\n| ------- | ------------------------------------------ | ------------------------------------ |\n| re      | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eRegExp\u003c/code\u003e | Name of route to match               |\n| handler | \u003ccode\u003efunction\u003c/code\u003e                      | Method to execute when route matches |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### remove(route, [handler]) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nRemove a route from the routerc\n\n| Param     | Type                                       | Description                |\n| --------- | ------------------------------------------ | -------------------------- |\n| re        | \u003ccode\u003estring\u003c/code\u003e \\| \u003ccode\u003eRegExp\u003c/code\u003e | Name of route to remove    |\n| [handler] | \u003ccode\u003efunction\u003c/code\u003e                      | Function handler to remove |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### reload() ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nReload the current route\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### listen([instance]) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nStart listening for hash changes on the window\n\n| Param      | Type             | Default             | Description                   |\n| ---------- | ---------------- | ------------------- | ----------------------------- |\n| [instance] | \u003ccode\u003eany\u003c/code\u003e | \u003ccode\u003eWindow\u003c/code\u003e | Context to start listening on |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### stopListen([instance]) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nStop listening for hash changes on the window\n\n| Param      | Type             | Default             | Description                  |\n| ---------- | ---------------- | ------------------- | ---------------------------- |\n| [instance] | \u003ccode\u003eany\u003c/code\u003e | \u003ccode\u003eWindow\u003c/code\u003e | Context to stop listening on |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### navigate(path) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nNavigate router to path\n\n| Param | Type                | Description                    |\n| ----- | ------------------- | ------------------------------ |\n| path  | \u003ccode\u003estring\u003c/code\u003e | Path to navigate the router to |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### navigateError(hash) ⇒ \u003ccode\u003eRouter\u003c/code\u003e\n\nNavigate to the error page\n\n| Param | Type                |\n| ----- | ------------------- |\n| hash  | \u003ccode\u003estring\u003c/code\u003e |\n\n_Returns_: \u003ccode\u003eRouter\u003c/code\u003e - This router instance\n\n\u003chr\u003e\n\n#### cleanPath(path) ⇒ \u003ccode\u003estring\u003c/code\u003e\n\nStrip the path of slashes and hashes\n\n| Param | Type                | Description             |\n| ----- | ------------------- | ----------------------- |\n| path  | \u003ccode\u003estring\u003c/code\u003e | Path to clean of hashes |\n\n_Returns_: \u003ccode\u003estring\u003c/code\u003e - Cleaned path\n\n\u003chr\u003e\n\n#### parseRoute(path) ⇒ \u003ccode\u003estring\u003c/code\u003e\n\nParse a route URL to get all parts\n\n| Param | Type                | Description               |\n| ----- | ------------------- | ------------------------- |\n| path  | \u003ccode\u003estring\u003c/code\u003e | Route to split into parts |\n\n_Returns_: \u003ccode\u003estring[]\u003c/code\u003e - Parts of the url\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisru%2Fes6-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisru%2Fes6-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisru%2Fes6-router/lists"}