lustre_routed
Lustre routed is a helper library for Lustre that helps create single-page-applications with the JS history routing API. It allows you to create applications with different routes without having a full-page refresh between the routes.
Types
When a route is passed to your view and loader functions it will be a list of strings. The path is split by its forward slashes, so that “/my/cool/route” gets split to [“my”, “cool”, “route”].
pub type Route =
List(String)
The internal action/message type which is used by the routed application.
pub opaque type RoutedAction(orig_action)
The internal state/model which is used by the routed application to track its own route state as well as your own state.
pub opaque type RoutedModel(model)
Functions
pub fn back() -> RoutedAction(a)
Used to pop the latest route off the browser’s history stack (equivalent to hitting the back button in the browser).
pub fn forward() -> RoutedAction(a)
Used to push the next route back onto the browser’s history stack (equivalent to hitting the forward button in the browser).
pub fn go_to(route: String) -> RoutedAction(a)
Used to push a new route into the browser’s history stack.
pub fn listen_for_navigation() -> Effect(RoutedAction(a))
Create a lustre effect that listens for changes in the browser’s history when the user hits the forward or backward buttons.
pub fn perform(action: a) -> RoutedAction(a)
Used to dispatch an action to your own internal state.
pub fn redirect(route: String) -> RoutedAction(a)
Used to replace the current route in the browser’s history.
pub fn routed_application(
init: fn(a) -> #(b, Effect(RoutedAction(c))),
update: fn(b, c) -> #(b, Effect(RoutedAction(c))),
loader: fn(List(String), b) -> Effect(RoutedAction(c)),
view: fn(List(String), b) -> Element(RoutedAction(c)),
) -> App(a, RoutedModel(b), RoutedAction(c))
Creates a lustre application which uses history-based routing.