Site / Creating a site
Link clicks and URL changes
Site.routing wires link clicks and URL changes once for the whole tree:
ts
import { ModelRef } from 'foldkit-surface'
const Routing = Site.routing<Model, Message, AppRoute>({
site: AppSite,
owner: App.owner,
route: {
dependency: ModelRef.focus(App.model.route).dependency,
get: model => model.route,
set: (model, route) => modifyFields(model, { route: () => route }),
},
parse: urlToAppRoute,
tags: { clicked: 'ClickedLink', changed: 'ChangedUrl' },
completed: Message.CompletedNavigation,
pages: [PeoplePage],
})
const assembly = Bundle.assemble<Model, Message>()([Routing, ...pages.map(page => page.placed)])
const update = assembly.update((model, message) =>
Routing.reduces(message) ? { model } : updateOwn(model, message),
)Clicking a link inside the tree pushes or replaces via Site.historyOf; links
outside the tree (Site.routeAt) perform full document loads. On URL changes,
Routing updates the route field (returning the Model unchanged on echoes),
notifies matched pages, and runs arrived(model, route) for post-navigation
effects such as moving focus. Routing.reduces(message) keeps click and
URL-change tags out of updateOwn while still letting URL mirrors read their
slices first.