Routing and the URL
Blocks that keep state in the URL go through a small router adapter, so a hash router keeps its route and an app with its own route contract keeps control.
The router adapter
MasterDetail url, SettingsPage url and ServerDataTable urlState never assume a router. They take an adapter, and the adapters can go through a UrlRouter from url-router: four functions over the app's location.
| Member | What it does |
|---|---|
read() | The location now: { path, params }. |
navigate(to, { replace }) | Goes there, adding a history entry unless replace. |
href(to) | The href of a location, for a link that opens in a new tab. |
subscribe(listener) | Calls listener when the location may have changed; returns the unsubscribe. |
| Router | Location | Use it with |
|---|---|---|
hashRouter() | #/devices?device=a1 | A router that reads location.hash: the path stays, the query changes, hrefs are #/path?query. |
historyRouter() | /devices?device=a1 | A router that reads the path and query string; the hash is kept on writes. |
memoryRouter(initial) | /devices?device=a1 | Tests and server rendering; it records entries. |
createUrlParam ships in the url-param item, which master-detail and settings-page install. Without router, createUrlParam(name) keeps its old behaviour: the value in location.search (or { in: "hash" } for a hash route's query).
Your router's own API
When the app's router rewrites URLs it didn't write, or a query on every route is unwelcome, wrap the router in the same shape. The blocks then navigate through it, and its links, guards and scroll handling stay in charge.
Settings section links
A SettingsPage navigation entry is a link, so it can open in a new tab. Its href comes from the url adapter: through hashRouter() it is #/settings?section=security, which fast links follow as a hash route on press and a new tab opens on the same route. Without url it is #security, an in-page anchor that stays native. getHref overrides both, and navigation="buttons" renders buttons that only scroll, for sections that have no address of their own.
Controlled selection
A route contract of the app's own, like a path segment per item, is not a query param. Skip the adapter and control the block from the route:
MasterDetail selectedId onSelectedIdChange: the route opens the item; a press, Close, Back or an agent calls back, anddetails.cancel()refuses.SettingsPage currentSection onSectionChange: the same for the section being read.