Extension points plugins register on the router at runtime — typically
from their lifecycle.on_start, which runs before the app's own
on_start starts the root screen. Nothing to configure in the app.
:before_navigate
Called with the destination (a screen module or a route atom) before a
navigation that mounts a screen — push_screen, reset_to (either
form). Pops and pop_to go back to screens already mounted and don't
call it. The hook returns:
:ok— navigate as usual.{:redirect, module}— mountmoduleinstead (e.g. a "please update" screen).{:error, reason}— refuse: navigation is left untouched and the current screen repaints, as for an unknown destination.
Hooks run in the order registered; the first non-:ok answer wins. A
hook that raises, exits, or returns anything else counts as
{:error, _}. It runs in the router process, so it must be fast when
there's nothing to do — a hook that has to fetch code (mob_deliver's
just-in-time screens) blocks navigation while it does.
:after_first_render
Called once per VM, in its own process, after the router's first paint
of the root screen: the supervision tree is up and the first screen has
mounted and been handed to the renderer. Not called by test routers that
don't render (Mob.Router.start_link/3).
Mob.Router.Hooks.register(:before_navigate, {MyPlugin, :before_navigate, []})
Mob.Router.Hooks.register(:after_first_render, {MyPlugin, :first_render, []})The destination is appended to a :before_navigate hook's arguments;
:after_first_render hooks get the arguments as given.