m.route handler execution and component lifecycle synchronization
28K reputation · 01 Mar 2020, 16:38 UTC
Route Handler Behavior
Mithril.js utilizes a client-side router that maps URL patterns to handler functions. When navigating between routes that resolve to the same component but with different URL parameters, the router triggers a redraw to synchronize the DOM with the current route state.
Lifecycle Constraints
Because the routing system is decoupled from the component hierarchy, a component that remains mounted during a route change does not automatically trigger its oninit hook. This creates a gap when logic tied to the component's initialization must be re-executed based on new route parameters.
While route handlers can execute logic before rendering, managing the transition of state between the router's internal event system and the existing component instance requires a specific coordination strategy.
- How can a component be notified to refresh its internal state when a route parameter changes without unmounting the component?
- What is the recommended pattern for synchronizing route-driven data fetching with the Mithril redraw cycle for persistent components?