Router
{ bind : Msg pageMsg -> msg
, parser : Url.Parser.Parser (route -> route) route
, notFound : Url -> route
, init : route -> ( page
, Platform.Cmd.Cmd pageMsg )
, update : pageMsg -> page -> ( page
, Platform.Cmd.Cmd pageMsg )
, view : page -> Layout pageMsg
, subscriptions : page -> Platform.Sub.Sub pageMsg
, options : Options route msg
}
Config
bind
Your router Msg eg RouterMsg (Router.Msg Page.Msg)
parser
Your Route
parser
notFound
Your not found Route
init
Your Page
init
update
Your Page
update
view
Your Page
view
subscriptions
Your Page
subscriptions
options
Router
options
{ cache : Cache route
, cacheExceptions : List String
, navigationDelay : Maybe Basics.Float
, onEvent : Maybe (Event -> msg)
}
Router options
cache cache strategy
cacheExceptions paths to ignore caching for, useful for pages like login where you don't want the inputs to remain filled.
navigation delay add delay to navigation so you can animate page transitions
onEvent receive notifications for Router events
Cache rules
defaultOptions : Options route msg
default options
Always use cache
No exceptions
No navigation delay
No events
Router
Msg
{ title : Maybe String
, attrs : List (Html.Attribute msg)
, main : List (Html msg)
}
Layout
title Set a title for each page.
attrs Attributes that will be set on the container.
main Html content to be set inside the container.
init : Config msg route page pageMsg -> Url -> Browser.Navigation.Key -> ( Router route page, Platform.Cmd.Cmd msg )
init
update : Config msg route page pageMsg -> Msg pageMsg -> Router route page -> ( Router route page, Platform.Cmd.Cmd msg )
update
view : Config msg route page pageMsg -> Router route page -> Layout msg
view
subscriptions : Config msg route page pageMsg -> Router route page -> Platform.Sub.Sub msg
subscriptions
onUrlChange : (Msg pageMsg -> msg) -> Url -> msg
onUrlChange
onUrlRequest : (Msg pageMsg -> msg) -> Browser.UrlRequest -> msg
onUrlRequest
mapUpdate : (model -> page) -> (msg -> pageMsg) -> ( model, Platform.Cmd.Cmd msg ) -> ( page, Platform.Cmd.Cmd pageMsg )
map update
mapView : (msgA -> msgB) -> Layout msgA -> Layout msgB
map view
url : Router route page -> Url
currentUrl
route : Router route page -> route
currentRoute
page : Router route page -> Maybe page
currentPage
viewport : Router route page -> Maybe Browser.Dom.Viewport
currentViewPort
base : Router route page -> Url
base
key : Router route page -> Browser.Navigation.Key
key
Might cause issues if used outside of router, not sure
redirect : Config msg route page pageMsg -> Router route page -> String -> ( Router route page, Platform.Cmd.Cmd msg )
redirect
reload : Config msg route page pageMsg -> Router route page -> ( Router route page, Platform.Cmd.Cmd msg )
reload
This never results in a page load! It will just re-init the current page
replaceUrl : Config msg route page pageMsg -> Router route page -> String -> ( Router route page, Platform.Cmd.Cmd msg )
replaceUrl
Same as redirect but uses `Browser.Navigation` replaceUrl
external : Config msg route page pageMsg -> Router route page -> String -> ( Router route page, Platform.Cmd.Cmd msg )
external
Same as redirect exept is an external link
Event
Basic router events