npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

lit-rout

v0.0.8

Published

Declarative, conditional rendering based on the Location for Lit applications

Readme

lit-rout

Please note: still a draft

Declarative, conditional rendering based on the Location for Lit applications.

Parts

  1. A lit-rout custom component registered by the library
  2. A custom component extended from lit-rout/RoutedLitComponent registered by the application

Check out https://www.npmjs.com/package/path-to-regexp#match about how to use route matching

Usage

HTML Template

<my-app>
  <lit-rout route="/">

    <!-- Custom Component that extends from lit-rout/RoutedLitElement -->
    <my-dashboard></my-dashboard>
    
    <!-- not a RoutedLitElement so updates for this are ignored -->
    <h3>I'm always rendered</h3>
    
  </lit-rout>

  <!-- nesting routes, "(.*)" signifies nesting. Required because routes are strictly matched -->
  <lit-rout route="/page(.*)">

    <my-page></my-page>
    
    <!-- nested route, will inherit all parent routes wihtout "(.*)" -->
    <lit-rout route="/:id">
      <my-page-with-route-params></my-page-with-route-params>
    </lit-rout>

  </lit-rout>
</my-app>

Custom RoutedLitElement

import { customElement } from 'lit/decorators';
import { RoutedLitElement } from 'lit-rout';

@customElement('my-dashboard')
export class MyDashboard extends RoutedLitElement<{}> {
  renderTemplate() {
    return html`<h2>Dashboard</h2`;
  }
}

@customElement('my-page')
export class MyPage extends RoutedLitElement<{}> {
  renderTemplate() {
    return html`<h2>Page</h2>`;
  }
}

@customElement('my-page-with-route-params')
export class MyPage extends RoutedLitElement<{ id: string }> {
  renderTemplate() {
    return html`<h2>Page ${this.params.id}</h2>`;
  }
}

About the components/API

Quick guide to the basic building blocks

lit-rout Custom Component

<lit-rout route="/path/to/success"><!-- content --></lit-rout>

A custom component registered by the library, with one attribute that should match (or not) the current URL.

This component will set the visible property on its child Elements. You will have to make sure that the child elements inherit from RoutedLitElement, otherwise they will be rendered at all times - match/update will ignore non-RoutedLitElements.

Can have multiple RoutedLitElements if needed.

RoutedLitElement Class

Just like a standard LitElement but:

  • (instead of the render method) you have to implement the renderTemplate method to return the HTML template,
  • class is generic, type is the interface/type describing the route params object
interface MyPageParams {
  id: string;
  title: string;
}

@customElement('my-page')
export class MyPage extends RoutedLitElement<MyPageParams> {
  renderTemplate() {
    const { id, title } = this.params // access the matched parameters from the URL - within the container lit-rout element !!!
    return html`<h2>My Page: ${name}/${id}</h2`;
  }
}

Please bear in mind that RoutedLitElements are always rendered, its their children that are de/attached (dis/connected) from the DOM so any lifecycle related logic should go into those components.

Extra

Parcel-TypeScript related issue that locks version to [email protected] for now.

In the future, when it's available, it would be awesome to use the URLPattern API