lue-bird/elm-state-interface/1.0.0

NOTE: the latest version is 2.0.4

Web.Navigation

Helpers for history interaction as part of an Interface

urlRequest : Interface AppUrl

An Interface for getting the current page's app-specific URL. Is usually used while starting up the app.

Note: Uses window.location.href

pushUrl : AppUrl -> Interface state_

An Interface that changes the app-specific URL and adds a new entry to the browser history, but does not trigger a page load.

Replacement for Browser.Navigation.pushUrl

replaceUrl : AppUrl -> Interface state_

An Interface that changes the app-specific URL, but neither triggers a page load nor adds a new entry to the browser history.

This can be useful if you have search box and you want the ?search=hats in the URL to match without adding a history entry for every single key stroke. Imagine how annoying it would be to click back thirty times and still be on the same page!

Replacement for Browser.Navigation.replaceUrl

moveForward : Int -> Interface state_

An Interface that goes forward a given number of pages. If there are no more pages in the future, this will do nothing.

Note: You only manage the browser history that you created.

Replacement for Browser.Navigation.forward

moveBack : Int -> Interface state_

An Interface that goes back a given number of pages.

Note: You only manage the browser history that you created.

Replacement for Browser.Navigation.back

movementListen : Interface AppUrl

If you used pushUrl to update the URL with new history entries, when the user clicks ← or → buttons (or you call moveForward or moveBack yourself), the URL will change but your UI will not.

Use movementListen to detect those URL changes and make ui changes as needed.

When the app itself initiates a url change with pushUrl or replaceUrl, no such event is triggered.

Note: This event is called "popstate" in js

load : Url -> Interface state_

An Interface that leaves the current page and loads the given URL. This always results in a page load, even if the provided URL is the same as the current one.

gotoElmWebsite : Web.Interface state_
gotoElmWebsite =
    Web.Navigation.load
        -- https://elm-lang.org/
        { protocol = Url.Https
        , host = "elm-lang.org"
        , port_ = Nothing
        , path = "/"
        , query = Nothing
        , fragment = Nothing
        }

Replacement for Browser.Navigation.load

reload : Interface state_

An Interface that reloads the current page. This always results in a page load!

Note: This may grab resources from the browser cache.

Replacement for Browser.Navigation.reload