| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Web.Spock.Browser.History
Description
Scoped History API navigation. Mount one router per window, and call
unmountRouter when its owner is removed. Same-origin links inside the scope
are intercepted; external, download, modified and same-page anchor clicks
retain their browser behavior. popstate and hashchange are deduplicated.
Synopsis
- data BrowserConfig = BrowserConfig {
- bc_scope :: Text
- bc_notFound :: Location -> IO ()
- bc_navigationError :: NavigationError -> IO ()
- data MountedRouter
- data HistoryMode
- mountRouter :: BrowserConfig -> Router -> IO (Either NavigationError MountedRouter)
- navigate :: MountedRouter -> HistoryMode -> Text -> IO (Either NavigationError ())
- currentLocation :: IO (Either NavigationError Location)
- unmountRouter :: MountedRouter -> IO ()
Documentation
data BrowserConfig Source #
Explicit URL scope and application handlers. Scope is / or an absolute
path prefix such as '/app'; prefix matching respects segment boundaries.
Constructors
| BrowserConfig | |
Fields
| |
data MountedRouter Source #
Owned listeners and callback. unmountRouter is idempotent. Queued events
are ignored after unmount; a handler already running is allowed to finish.
data HistoryMode Source #
Add a history entry or replace the current entry. Navigating to the current URL rerenders without adding a duplicate history entry.
Instances
| Show HistoryMode Source # | |
Defined in Web.Spock.Browser.History Methods showsPrec :: Int -> HistoryMode -> ShowS show :: HistoryMode -> String showList :: [HistoryMode] -> ShowS | |
| Eq HistoryMode Source # | |
Defined in Web.Spock.Browser.History | |
mountRouter :: BrowserConfig -> Router -> IO (Either NavigationError MountedRouter) Source #
Attach listeners and synchronously render the current in-scope URL. Navigation handlers run serially, in event order. Mounting twice returns AlreadyMounted; if the initial handler throws, listeners are cleaned up.
navigate :: MountedRouter -> HistoryMode -> Text -> IO (Either NavigationError ()) Source #
Navigate to a validated local URL within this router's scope. Rendering is queued through the same callback as link clicks, so handlers may navigate again without deadlocking. History API failures leave rendering unchanged.
currentLocation :: IO (Either NavigationError Location) Source #
Read the current browser path, query and fragment without exposing origin or credentials. Query strings remain encoded for application-specific parsing.
unmountRouter :: MountedRouter -> IO () Source #
Remove all listeners and release the Haskell callback exactly once.