I’ve published a small package that gives you SPA-style URL navigation using Browser.element and ports, without needing Browser.application.
I’ve been doing this thing for many apps, so it was time I just made a helper package for myself and whoever might find it useful.
Elm: mpizenberg/elm-url-navigation-port
JS companion (npm): elm-url-navigation-port
Source + example: GitHub
Why?
I often recommend staying on Browser.element for its simplicity and better compatibility with external JS libraries and browser extensions. But it doesn’t come with URL navigation built in. This package fills that gap with two ports and a tiny JS companion (~50 lines).
As a bonus, it exposes history.pushState with state objects — something Browser.application doesn’t offer. This enables patterns like multi-step wizards that support the back button without changing the URL.
What it provides
Four navigation patterns:
pushUrl— standard SPA page navigationpushState— push a state object without changing the URL (great for wizard steps)back/forward— traverse history by N stepsreplaceUrl— cosmetic URL updates without notifying Elm
All URLs go through lydell/elm-app-url, so they’re always same-origin by construction.
The example/ directory has a full working demo with all four patterns. That’s the video demo at the top of this post.
Enjoy!