Created
October 3, 2018 16:55
-
-
Save Pilatch/c1b6e5d925c6479a0b2e53892fa2dca3 to your computer and use it in GitHub Desktop.
Test anchor tag behavior for Elm debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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