{"id":17366148,"url":"https://github.com/aaronshaf/html-router","last_synced_at":"2025-05-07T18:41:00.298Z","repository":{"id":57094029,"uuid":"144872601","full_name":"aaronshaf/html-router","owner":"aaronshaf","description":"Drop-in router using web components","archived":false,"fork":false,"pushed_at":"2018-09-29T02:10:04.000Z","size":37,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T06:09:01.710Z","etag":null,"topics":["custom-elements","router","web-components"],"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/aaronshaf.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-08-15T15:45:59.000Z","updated_at":"2022-10-30T10:40:58.000Z","dependencies_parsed_at":"2022-08-22T21:40:51.243Z","dependency_job_id":null,"html_url":"https://github.com/aaronshaf/html-router","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronshaf%2Fhtml-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronshaf%2Fhtml-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronshaf%2Fhtml-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronshaf%2Fhtml-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronshaf","download_url":"https://codeload.github.com/aaronshaf/html-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252936074,"owners_count":21828070,"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":["custom-elements","router","web-components"],"created_at":"2024-10-15T21:29:44.503Z","updated_at":"2025-05-07T18:41:00.278Z","avatar_url":"https://github.com/aaronshaf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Drop-in router.\n\n## Usage\n\n### Hash router\n\n```html\n\u003cscript src=\"https://unpkg.com/@aaronshaf/html-router@1/hash.js\" type=\"module\"\u003e\u003c/script\u003e\n```\n\n#### Render first match ([example](https://aaronshaf.github.io/html-router/examples/hash-switch.html))\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\u003ca href=\"#/foo\"\u003eFoo\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#/bar\"\u003eBar\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#/baz\"\u003eBaz\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n```html\n\u003chash-switch\u003e\n  \u003ctemplate data-path=\"/foo\"\u003e\n    \u003ch1\u003eFoo\u003c/h1\u003e\n  \u003c/template\u003e\n\n  \u003ctemplate data-path=\"/bar\"\u003e\n    \u003ch1\u003eBar\u003c/h1\u003e\n  \u003c/template\u003e\n\n  \u003ctemplate data-path=\"(.*)\"\u003e\n    \u003ch1\u003eNot found\u003c/h1\u003e\n  \u003c/template\u003e\n\u003c/hash-switch\u003e\n```\n\n#### Standalone routes ([example](https://aaronshaf.github.io/html-router/examples/hash-route.html))\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\u003ca href=\"#/\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#/foo\"\u003eFoo\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#/foo/bar\"\u003eFoo and Bar\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n```html\n\u003chash-route path=\"/\"\u003e\n  \u003ch2\u003eHome\u003c/h2\u003e\n\u003c/hash-route\u003e\n\n\u003chash-route path=\"/foo(.*)\"\u003e\n  \u003ch2\u003eFoo\u003c/h2\u003e\n\u003c/hash-route\u003e\n\n\u003chash-route path=\"/foo/bar\"\u003e\n  \u003ch2\u003eBar\u003c/h2\u003e\n\u003c/hash-route\u003e\n```\n\n### Pathname router\n\n```html\n\u003cscript src=\"https://unpkg.com/@aaronshaf/html-router@1/pathname.js\" type=\"module\"\u003e\u003c/script\u003e\n```\n\n#### Render first match ([example](https://aaronshaf.github.io/html-router/examples/pathname-switch.html))\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\n    \u003cpushstate-link\u003e\u003ca href=\"/foo\"\u003eFoo\u003c/a\u003e\u003c/pushstate-link\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\n    \u003cpushstate-link\u003e\u003ca href=\"/bar\"\u003eBar\u003c/a\u003e\u003c/pushstate-link\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\n    \u003cpushstate-link\u003e\u003ca href=\"/baz\"\u003eBaz\u003c/a\u003e\u003c/pushstate-link\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n```html\n\u003cpathname-switch\u003e\n  \u003ctemplate data-path=\"/foo\"\u003e\n    \u003ch1\u003eFoo\u003c/h1\u003e\n  \u003c/template\u003e\n\n  \u003ctemplate data-path=\"/bar\"\u003e\n    \u003ch1\u003eBar\u003c/h1\u003e\n  \u003c/template\u003e\n\n  \u003ctemplate data-path=\"(.*)\"\u003e\n    \u003ch1\u003eNot found\u003c/h1\u003e\n  \u003c/template\u003e\n\u003c/pathname-switch\u003e\n```\n\n#### Standalone routes ([example](https://aaronshaf.github.io/html-router/examples/pathname-route.html))\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\n    \u003cpushstate-link\u003e\u003ca href=\"/foo\"\u003eFoo\u003c/a\u003e\u003c/pushstate-link\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\n    \u003cpushstate-link\u003e\u003ca href=\"/foo/bar\"\u003eFoo \u0026 Bar\u003c/a\u003e\u003c/pushstate-link\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n```html\n\u003cpathname-route path=\"/foo(.*)\"\u003e\n  \u003ch2\u003eFoo\u003c/h2\u003e\n\u003c/pathname-route\u003e\n\n\u003cpathname-route path=\"/foo/bar\"\u003e\n  \u003ch2\u003eBar\u003c/h2\u003e\n\u003c/pathname-route\u003e\n```\n\n## Access match params\n\nCustom elements that are children of a route or switch can access match data at `this.match`.\n\n## Prevent flash of undefined content\n\n```html\n\u003cstyle\u003e\nhash-switch:not(:defined),\npathname-switch:not(:defined) {\n  visibility: hidden;\n}\n\u003c/style\u003e\n```\n\n## Web components polyfill\n\n```html\n\u003cscript src=\"https://unpkg.com/@webcomponents/webcomponentsjs@2/webcomponents-loader.js\"\u003e\u003c/script\u003e\n```\n\n## See also\n\n* [element-router](https://github.com/filipbech/element-router)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronshaf%2Fhtml-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronshaf%2Fhtml-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronshaf%2Fhtml-router/lists"}