Skip to content

Instantly share code, notes, and snippets.

@Pilatch
Created October 3, 2018 16:55
Show Gist options
  • Save Pilatch/c1b6e5d925c6479a0b2e53892fa2dca3 to your computer and use it in GitHub Desktop.
Save Pilatch/c1b6e5d925c6479a0b2e53892fa2dca3 to your computer and use it in GitHub Desktop.
Test anchor tag behavior for Elm debugging
module Main exposing (main)
import Browser exposing (..)
import Browser.Navigation as Nav
import Html exposing (Html, a, button, div, text)
import Html.Attributes exposing (href, id)
import Html.Events exposing (onClick)
import Url
type alias Model =
{ key : Nav.Key
}
initialModel key =
{ key = key }
type Msg
= ClickedLink UrlRequest
| NoOp
init flags url key =
( initialModel key, Cmd.none )
update msg model =
case msg of
ClickedLink urlRequest ->
case urlRequest of
Internal url ->
( model
, Nav.pushUrl model.key (Url.toString url)
)
External url ->
( model
, Nav.load url
)
NoOp ->
( model, Cmd.none )
document model =
{ title = "Hello"
, body = [ view model ]
}
view : Model -> Html Msg
view model =
div []
[ a [] [ text "go nowhere" ]
, Html.br [] []
, Html.br [] []
, a [ href "" ] [ text "go blank!" ]
, Html.br [] []
, Html.br [] []
, a [ href "/" ] [ text "go slash!" ]
, Html.br [] []
, Html.br [] []
, a [ href "/bibibibibi" ] [ text "go to bibibibibi!" ]
, Html.br [] []
, Html.br [] []
, a [ href " " ] [ text "go to space!" ]
, Html.br [] []
, Html.br [] []
, a [ href "https://google.com" ] [ text "googz" ]
]
main : Program () Model Msg
main =
Browser.application
{ init = init
, view = document
, update = update
, subscriptions = always Sub.none
, onUrlRequest = ClickedLink
, onUrlChange = always NoOp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment