How can I redirect to external url? I've tried with Navigation
module, but it seems to work only for local routes. Is there a way to do it natively, without js ports?
I.e. window.location.href = http://google.com;
Edit: I somehow missed Navigation.load
function. As suggested below, it will help with redirects.
Since a
tag can be always used with specified href
, I'd rather try to find a solution which would avoid using redirection from update
function.
a [ href "http://google.com" ] [ text "Google link" ]
But in case it's necessary to implement the logic similar to window.location.href = "http://google.com";
, elm-lang/navigation
provides load function (and a couple of other useful ones for forcing page loads) which does, what you're expecting.
It takes a url and returns a command load : String -> Cmd msg
, so it's going to look like this:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
RedirectToGoogle ->
( model, load "http://google.com" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With