{"id":17321769,"url":"https://github.com/avoidwork/dom-router","last_synced_at":"2025-04-14T16:02:04.918Z","repository":{"id":25093303,"uuid":"28514274","full_name":"avoidwork/dom-router","owner":"avoidwork","description":"URL hash to DOM router","archived":false,"fork":false,"pushed_at":"2022-09-23T21:00:34.000Z","size":908,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T16:50:47.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://avoidwork.github.io/dom-router","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avoidwork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["avoidwork"]}},"created_at":"2014-12-26T15:34:13.000Z","updated_at":"2022-08-25T14:49:25.000Z","dependencies_parsed_at":"2022-08-26T13:31:34.062Z","dependency_job_id":null,"html_url":"https://github.com/avoidwork/dom-router","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Fdom-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Fdom-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Fdom-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Fdom-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avoidwork","download_url":"https://codeload.github.com/avoidwork/dom-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565060,"owners_count":21125415,"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-15T13:39:31.923Z","updated_at":"2025-04-14T16:02:04.892Z","avatar_url":"https://github.com/avoidwork.png","language":"JavaScript","funding_links":["https://github.com/sponsors/avoidwork"],"categories":[],"sub_categories":[],"readme":"# dom-router\n\nImagine you didn't have to write a bunch of JavaScript to get a slick, progressively enhanced interface! `dom-router`\nis a URL hash to DOM router which automatically, \u0026 intelligently toggles visibility of `Elements` based on `popstate`\nevents.\n\nThis provides a clean separation of concerns, and progressive enhancement in a simple library. You can write clean HTML,\nand `dom-router` will progressively enhance the interface with CSS classes (not supplied). DOM updates happen on an\nanimation frame to minimize impacting your application. An optional `callback` allows you to handle application\nstate changes the way you want.\n\n## Example\nThis example is meant to demonstrate multi-tier routing in a single page application. When the HTML is \"clean\", it is\nfunctional for screen readers \u0026 text based browsers like `lynx`, and with progressive enhancement, developers can add\nnew behaviour without impacting the experience of other consumers.\n\n### Minimal coding required\n```javascript\nimport {router} from \"./dom-router.js\";\nwindow.appRouter = router({callback: arg =\u003e console.log(`${arg.element.id} is visible`)});\n```\n\n### Before routing is enabled\n```html\n\u003cnav\u003e\n  \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"#main\"\u003eMain\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/billing\" class=\"settings\"\u003eBilling\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/password\" class=\"settings\"\u003ePassword\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/avatar\" class=\"settings\"\u003eAvatar\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/nav\u003e\n...\n\u003carticle\u003e\n  \u003csection id=\"main\"\u003e...\u003c/section\u003e\n  \u003csection id=\"settings\"\u003e\n    \u003csection id=\"billing\"\u003e...\u003c/section\u003e\n    \u003csection id=\"password\"\u003e...\u003c/section\u003e\n    \u003csection id=\"avatar\"\u003e...\u003c/section\u003e\n  \u003c/section\u003e\n\u003c/article\u003e\n```\n\n### After routing is enabled\nThis would be the result if a user visited `#settings/billing`:\n\n```html\n\u003cnav\u003e\n  \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"#main\"\u003eMain\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/billing\" class=\"settings dr-current\"\u003eBilling\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/password\" class=\"settings\"\u003ePassword\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#settings/avatar\" class=\"settings\"\u003eAvatar\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/nav\u003e\n...\n\u003carticle\u003e\n  \u003csection id=\"main\" class=\"dr-hidden\"\u003e...\u003c/section\u003e\n  \u003csection id=\"settings\"\u003e\n    \u003csection id=\"billing\"\u003e...\u003c/section\u003e\n    \u003csection id=\"password\" class=\"dr-hidden\"\u003e...\u003c/section\u003e\n    \u003csection id=\"avatar\" class=\"dr-hidden\"\u003e...\u003c/section\u003e\n  \u003c/section\u003e\n\u003c/article\u003e\n```\n\n## How can I load dom-router?\nWhen loaded with a script tag, `window.domRouter.router()` will be created.\n\n## Configuration\n### active\n`Boolean` which enables/disables routing\n\n### callback\nFunction to execute after route has changed, takes `arg` which describes the event\n\n### css\n`Object` with `current`, \u0026 `hidden` keys which have corresponding CSS class values, defaults to \"dr-current\", \u0026 \"dr-hidden\"\n\n### ctx\nContext for DOM selector, defaults to `body` if not specified\n\n### delimiter\nMulti-tier routing delimiter, defaults to `/`, e.g. `#settings/billing`; each tier should map to a nested `id`\n\n### logging\n`Boolean` which logs routing to `router.history[]` if `true`, defaults to `false`; could be a memory leak if logging is enabled and target `Elements` are removed from DOM\n\n### start\n[Optional] The starting route to display if one is not specified, or an invalid route is specified\n\n### stickyPos\n`Boolean` which enables/disables remaining at `Y position` when the route changes, i.e. no scrolling, defaults to `true`.\n\n### stickyRoute\n`Boolean` which enables/disables sticky routing, defaults to `true`.\n\n### stickySearchParams\n`Boolean` which enables/disables sticky `searchParams` of `location`, defaults to `false`. When it disabled `history.replaceState()` is executed on `location` before `callback()`.\n\n### storage\n`String` Storage used for `stickyRoute`, defaults to `session`; valid options are `session` or `local`.\n\n### storageKey\n`String` Key for persistent storage for `stickyRoute`.\n\n## API\n### current()\nReturns the current `Route`; if logging is enabled the trigger `Element` will be present\n\n### popstate()\nEvent handler\n\n### scan(default)\nScans `ctx` for routes \u0026 resets `default` which is an optional argument, otherwise it defaults to the first route\n\n### select(query)\nContext specific DOM selector\n\n\n## Requirements\n- `Element.classList` API, or shim\n- `popstate` Event\n\n## License\nCopyright (c) 2022 Jason Mulligan\nLicensed under the BSD-3 license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Fdom-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favoidwork%2Fdom-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Fdom-router/lists"}