Skip to content

Instantly share code, notes, and snippets.

@developit
Last active July 25, 2023 12:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developit/36c2d788feb6437c5f933903cb7651e1 to your computer and use it in GitHub Desktop.
Save developit/36c2d788feb6437c5f933903cb7651e1 to your computer and use it in GitHub Desktop.
import regexparam from 'https://unpkg.com/regexparam@1/dist/regexparam.mjs';
/**
* <url-route href="/profile/:user">
* <div>some content here</div>
* </url-route>
*/
customElements.define('url-route', class UrlRoute extends HTMLElement {
connectedCallback() {
this.route = regexparam(this.getAttribute('href'));
const show = this.route.pattern.test(location.pathname);
this.children.forEach(c => c.style.display = show ? '' : 'none');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment