You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(routing): add routing documentation and route directive reference (#90)
### Why
Routing is a core feature that touches every layer of WebUI — protocol, parser,
handler, FFI, and a new client-side router package. Before reviewing any code,
reviewers need to understand what the routing system does, how servers and clients
interact, and what contract they follow. Shipping docs first gives reviewers
(and future contributors) the full mental model before the implementation lands.
### What
Two new documentation pages and updates across existing docs:
- **`<route>` directive reference** — documents the HTML syntax developers write:
`path`, `name`, `component`, `exact` attributes, parameter segments (`:id`,
`:id?`, `*splat`), specificity-based matching, and how the server renders
matched vs non-matched routes during SSR.
- **Routing guide** — end-to-end walkthrough of the routing system: installing
`@microsoft/webui-router`, starting the `Router` class after hydration,
opt-in lazy loading with dynamic imports, the `webui:route:navigated` event,
and critically the **server contract for JSON partials** — when the client
navigates, it sends `Accept: application/json` with an inventory bitmask,
and the server returns `{ state, templates, inventory, path }` instead of
full HTML. Includes implementation examples for Node/Express and C#/.NET.
- **Handler docs updated** — all platform handler pages (Rust, Node, FFI) now
show the new `RenderOptions` parameter with `entry_id` and `request_path`,
so developers aren't surprised by the signature change in later PRs.
- **Installation page** — added `@microsoft/webui-router` as an optional
dependency with install commands and a link to the routing guide.
- **Router npm README** — package-level documentation for npmjs.com: quick
start, API reference, path syntax table, lazy loading setup, server contract.
### How
Docs-only PR — no Rust or TypeScript logic changes. The handler doc examples
reference `RenderOptions` which doesn't exist on `main` yet (it lands in PR3).
This is intentional: the docs describe the target API so reviewers can evaluate
the design before the implementation.
The `<route>` directive defines a client-side route that maps a URL path to a component. At build time, `<route>` elements are compiled into `<webui-route>` custom elements. At runtime, the server renders the matched route's component and the client router handles subsequent navigations.
The server matches the request path against the defined routes and renders the matching component with its state. Non-matching routes are rendered hidden.
16
+
17
+
## Attributes
18
+
19
+
| Attribute | Required | Description |
20
+
|-----------|----------|-------------|
21
+
|`path`| Yes | URL path template to match (e.g., `/users/:id`) |
22
+
|`component`| Yes | Tag name of the component to render (e.g., `user-detail`) |
23
+
|`name`| No | Unique name for the route (used in navigation events) |
24
+
|`exact`| No | Only match when the path matches exactly (no prefix matching) |
25
+
26
+
## Path Parameters
27
+
28
+
Route paths support dynamic segments that capture values from the URL:
A request to `/users/add` matches the first route (2 literal segments) over the second (1 literal + 1 param).
70
+
71
+
## Exact vs Prefix Matching
72
+
73
+
By default, routes use prefix matching — `/users` matches `/users`, `/users/42`, and `/users/42/edit`. Add the `exact` attribute to require a full match:
Copy file name to clipboardExpand all lines: docs/guide/concepts/handlers/index.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,12 +27,13 @@ This consistent approach ensures that the same template produces identical resul
27
27
While the specific implementation details vary between languages, all handlers provide a similar API:
28
28
29
29
```
30
-
handle(protocol, state, writer)
30
+
handle(protocol, state, options, writer)
31
31
```
32
32
33
33
Where:
34
34
-`protocol` is the WebUI protocol object
35
35
-`state` is the data object with values to be rendered
36
+
-`options` specifies the entry fragment and request path for [route matching](/guide/concepts/routing)
36
37
-`writer` is a callback or interface for writing the rendered output
37
38
38
39
## Plugin System
@@ -41,7 +42,7 @@ Handlers support an optional **plugin system** for injecting framework-specific
41
42
42
43
```
43
44
handler = Handler::with_plugin(plugin)
44
-
handler.handle(protocol, state, writer)
45
+
handler.handle(protocol, state, options, writer)
45
46
```
46
47
47
48
When no plugin is configured, the handler renders plain HTML. When a plugin is loaded (e.g., `FastHydrationPlugin`), it injects markers that enable client-side hydration.
0 commit comments