module UI::Web

Defined in:

ui/renderers/web_renderer.cr

Class Method Summary

Class Method Detail

def self.render_route_host(routes : Hash(String, String), initial_route : String, route_change_announce_label : String = "Navigated to {route}") : String #

Phase 6.10 D2 — coordinator-driven route host

The web target is a single-page HTML doc with hash-route navigation. Each route's view tree is rendered once at build time + once per push/pop at runtime, in the browser, via a tiny vanilla-JS shim. The shim listens to hashchange + popstate and swaps the host element's innerHTML to the new route's pre-rendered HTML fragment.

render_route_host(routes) emits:

  1. The host <div id="ui-route-host">…</div> containing the INITIAL route's fragment.
  2. A <script type="application/json" id="ui-route-data">… block carrying every route's pre-rendered HTML keyed by route id.
  3. A <script> that wires hashchange → DOM swap.

routes is Hash(String, String) of route_id_str => prerendered_html. initial_route is the route shown before any hash navigation. route_change_announce_label is the aria-live announcement template (default "Navigated to {route}") used for I-6 a11y compliance.


[View source]