Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when using pushUrl with --debug flag on. #10

Closed
ChristophP opened this issue Jul 1, 2018 · 0 comments
Closed

Runtime error when using pushUrl with --debug flag on. #10

ChristophP opened this issue Jul 1, 2018 · 0 comments

Comments

@ChristophP
Copy link

ChristophP commented Jul 1, 2018

Compiling with the --debug flag makes this SSCCE crash with a runtime error when the button is clicked: key.a is not a function. There is no runtime error when --debug is ommitted

module Main exposing (..)

import Browser
import Browser.Events
import Browser.Navigation as Nav
import Html exposing (..)
import Html.Events exposing (onClick)
import Json.Decode as JD
import Tuple exposing (pair)
import Url
import Url.Builder

main =
    Browser.application
        { init = init
        , view = view
        , update = update
        , subscriptions = \_ -> Sub.none
        , onUrlRequest = LinkClicked
        , onUrlChange = UrlChange
        }

type alias Model =
    { key : Nav.Key }

init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )

init env _ key =
    pair { key = key } Cmd.none

view : Model -> Browser.Document Msg

view model =
    { title = "My app"
    , body =
        [ Html.h2 [] [ text "Elm 19" ]
        , button [ onClick ButtonClick ]
            [ text "Click Me" ]
        ]
    }

type Msg = LinkClicked Browser.UrlRequest | UrlChange Url.Url | ButtonClick

update msg model =
    case msg of
        LinkClicked urlRequest ->
            case urlRequest of
                Browser.Internal url ->
                    ( model, Nav.pushUrl model.key (Url.toString url))
                Browser.External url ->
                    ( model, Nav.load url)
        UrlChange url ->
            pair model Cmd.none
        ButtonClick ->
            pair model <| Nav.pushUrl model.key (Url.Builder.absolute [ "hello" ] [])
@ChristophP ChristophP changed the title Runtime error when using with --debug flag and pushUrl. Runtime error when using pushUrl with --debug flag on. Jul 1, 2018
@evancz evancz closed this as completed in 83cc532 Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant