Sample App
The sample app is a webmail + contacts client that puts lit-ui-router's guides together in one running application: nested and named views, protected routes with a login flow, lazy-loaded feature modules, sticky states, unsaved-changes guards, 404 handling, and a live feature-flags panel for switching location plugins.
Authentication is mocked locally — pick any user and enter password to sign in.
What it demonstrates
| Feature | Source file | Guide |
|---|---|---|
| Route guards & login redirect | requiresAuth.hook.ts, Login.ts | Route Guards |
Lazy-loaded .** future states | main/states.ts | Routed Components |
Named views (mymessages, contacts, messagelist, messagecontent) | App.ts, MyMessages.ts, mymessages/states.ts | Named Views |
Unsaved-changes guard (uiCanExit) | contacts/EditContact.ts | Component Lifecycle Hooks |
| Sticky states & deep state redirect | contacts/states.ts, mymessages/states.ts | @uirouter/sticky-states, @uirouter/dsr |
| Location plugins & runtime switching | prefs/FeatureFlagsPanel.ts | Location Plugins |
| Unmatched URLs & server verdicts | main/NotFound.ts, routes.ts | Unmatched URLs (404), Server-Side Routing |
| Typed state names | registry/states.ts, contacts/states.ts | ui-router-registry |
Devtools and visualizer
The sample app includes an in-repo devtools panel showing the state tree and each transition. Append ?feature-enable-visualizer=true to any mount's URL to also load @uirouter/visualizer (add &feature-enable-devtools=false to run the visualizer on its own).
API viewer
Append ?feature-enable-api-docs=true to show an API viewer below the app. It reads lit-ui-router/custom-elements.json and lists the properties, attributes and events of the elements lit-ui-router defines. It is off by default.
Live mounts
The same routing table is deployed in four client-state variants (all behind the same route-aware edge worker) plus a hash-location build:
| Mount | Spectrum level | Client state & routing |
|---|---|---|
/app | 3+4 | Vanilla (TransitionController) — flagship route-aware server (shell for real routes, computed 302s, real 404s). |
/app-mobx | 3+4 | MobX — identical routes and server verdicts, with client state in MobX stores. |
/app-effect | 3+4 | Effect — identical routes and server verdicts, with client state in SubscriptionRefs. |
/app-signals | 3+4 | Signals — identical routes and server verdicts, with client state in TC39 Signals via @lit-labs/signals. |
/app-hash | 1 | Hash location — the route lives in the fragment, so the server serves the shell at 200 at the mount root and needs no routing verdicts. |
Server-semantics exhibits
Three additional noindex mounts deploy the same app behind different server configurations so you can compare each point on the server-support spectrum side by side:
| Mount | Spectrum level | What it shows |
|---|---|---|
/not-found-naive | 2 | The anti-pattern baseline: every path answers 200 with the shell, no matching at all — the soft-404 fallback most SPAs ship. noindex. |
/not-found-spa | 4 | Shell-at-404: real routes serve the shell at 200; only a genuine miss serves the app shell at an honest 404, where the client renders its in-app 404 view. noindex. |
/simulated-routing | 5 | Every verdict computed by a real headless @uirouter/core router replaying the URL per request — redirects and otherwise() run as real rules. noindex. |
Two axes, one app
Across the routing axis — /app, /app-hash, and the three exhibits above — the mounts differ only in the HTTP verdict a URL earns (the four /app* variants share the same route table and verdicts, varying only client-state bindings). The Server-Side Routing guide is the deep dive on that routing axis.
How the page body is rendered is a separate choice: it does not change which status or redirect a URL gets. Today the sample app mounts are client-rendered throughout; build-time prerendering (Prerender with Vite, Prerender with Eleventy) and request-time server rendering (Rendering one page per request) live in lit-ui-router-ssr.
Source
The repository's lint runs the eslint-plugin-lit-ui-router rules over every app. Compare the four client-state entry points side by side against the shared routing and UI layers:
- Vanilla app —
apps/sample-app-lit-vanilla - MobX app —
apps/sample-app-lit-mobx - Effect app —
apps/sample-app-lit-effect - Signals app —
apps/sample-app-lit-signals - Shared app implementation —
apps/sample-app-shared - Shared routing projection — the route, redirect, and mount tables the edge worker imports:
apps/sample-app-routes - Edge worker — turns each verdict into HTTP:
www/lit-ui-router.dev/worker/index.ts