@diso.io

groutcho › Other frameworks › Lit @diso.io/groutcho-lit

Guide

Lit bindings for groutcho-core: a ReactiveController, a @lit/context context, and <diso-outlet> / <diso-link> elements. Use it to route a Lit app without the rest of diso.

npm install @diso.io/groutcho-lit lit @lit/context
import { LitElement, html } from 'lit';
import { RouterController } from '@diso.io/groutcho-lit';

class MyApp extends LitElement {
  router = new RouterController(this, { routes, redirects });

  render() {
    const { match } = this.router;
    return html`
      <nav>
        <diso-link .store=${this.router.store} to="Home">Home</diso-link>
        <diso-link .store=${this.router.store} to="/show/hi">Show</diso-link>
      </nav>
      <diso-outlet .store=${this.router.store}></diso-outlet>
    `;
  }
}
  • RouterController — binds an element to a store (or a config), re-rendering on navigation. Exposes .match and .go.
  • routerContext — provide one store, consume it in nested elements.
  • <diso-outlet> — renders match.route.page (called as (match) => TemplateResult when it's a function; override with .renderPage).
  • <diso-link> — an <a> that navigates via the router; modifier/middle clicks fall through.

Re-exports groutcho-core for a single import surface. See the groutcho family README.

This page as Markdown