| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Subscription.History
Contents
Description
Overview
Miso.Subscription.History wraps the browser's History API and popstate event, providing both a reactive subscription and imperative navigation helpers.
Subscriptions
uriSub fires whenever the URL changes — through browser back/forward
buttons or any of the imperative helpers below:
subs :: [SubAction] subs = [uriSubUrlChanged ]
routerSub is a convenience wrapper that decodes the URI via a
Router instance before delivering it as an action:
subs = [routerSub(RouteChanged .fromRightNotFound) ]
Imperative navigation
These functions push or replace entries on the browser history stack and
simultaneously fire a synthetic popstate event so that uriSub and
routerSub are notified automatically:
update GoHome =io_(pushURI(toURIHome)) update GoProfile =io_(pushRoute(User (Capture 42))) update ReplaceUrl =io_(replaceURInewUri) update GoBack =io_backupdate GoForward =io_forwardupdate (Jump n) =io_(gon)
getURI reads the current URL from window.location without subscribing:
update Init =io(GotURI <$>getURI)
See also
- Miso.Router —
Router,URI,toURI,prettyURI - Miso.Subscription — re-export hub
- Miso.Subscription.Util —
createSubused internally
Subscription
Arguments
| :: Router route | |
| => (Either RoutingError route -> action) | Callback fired with the decoded route (or |
| -> Sub action |
Subscription for popstate events, from the History API, mapped
to a user-defined Router.
Functions
Retrieves the current relative URI by inspecting pathname, search
and hash.
Pushes a new URI onto the History stack. Also raises a popstate event.
Arguments
| :: Router route | |
| => route | The route to push onto the history stack (converted to a URI internally) |
| -> IO () |
Pushes a new Route onto the History stack. Also raises a popstate event.
Converts the Route to a URI internally.
Replaces current URI on stack. Also raises a popstate event.
Jumps to a specific position in history.
Types
URI type. See the official specification
Constructors
| URI | |
Fields
| |