Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm lang redirect to external URL

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.

like image 218
Ilya Avatar asked Sep 20 '17 06:09

Ilya


1 Answers

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" )
like image 186
Igor Drozdov Avatar answered Nov 17 '22 05:11

Igor Drozdov