Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created October 4, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/d48cd92725ab7ea764c708856b94b14e to your computer and use it in GitHub Desktop.
Save Janiczek/d48cd92725ab7ea764c708856b94b14e to your computer and use it in GitHub Desktop.
SPA navigation
main : Program Flags Model Msg
main =
Browser.application
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
, onUrlChange = PathChange
, onUrlRequest = LinkClicked
}
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
PathChange urlString ->
-- decode the URL into a route, handle `onPathChange` hooks, etc.
LinkClicked request ->
case request of
Internal linkUrl ->
( model
, linkUrl
|> Url.toString
|> Browser.Navigation.pushUrl model.navKey
)
External linkUrl ->
( model
, Browser.Navigation.load linkUrl
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment