diff --git a/example/src/Pages/Counter.elm b/example/src/Pages/Counter.elm index 12677fe..963f42d 100644 --- a/example/src/Pages/Counter.elm +++ b/example/src/Pages/Counter.elm @@ -7,6 +7,7 @@ module Pages.Counter exposing import Application import Html exposing (..) +import Html.Attributes as Attr import Html.Events as Events @@ -57,5 +58,8 @@ view model = [ button [ Events.onClick Decrement ] [ text "-" ] , p [] [ text (String.fromInt model.counter) ] , button [ Events.onClick Increment ] [ text "+" ] + , p [] + [ a [ Attr.href "/#section" ] [ text "bottom of homepage" ] + ] ] ] diff --git a/example/src/Pages/Homepage.elm b/example/src/Pages/Homepage.elm index d443e82..b4b1fad 100644 --- a/example/src/Pages/Homepage.elm +++ b/example/src/Pages/Homepage.elm @@ -7,6 +7,7 @@ module Pages.Homepage exposing import Application import Html exposing (..) +import Html.Attributes as Attr type alias Model = @@ -33,4 +34,8 @@ view = div [] [ h1 [] [ text "Homepage" ] , p [] [ text "How exciting!" ] + , a [ Attr.href "#section" ] [ text "jump link" ] + , div [ Attr.style "height" "200vh" ] [] + , h3 [ Attr.id "section" ] [ text "you found me!" ] + , p [] [ text "(and i'm not even mad)" ] ] diff --git a/src/Application.elm b/src/Application.elm index 8de66fa..b6c39c5 100644 --- a/src/Application.elm +++ b/src/Application.elm @@ -14,6 +14,7 @@ module Application exposing @docs Application, create @docs Page, Recipe + @docs Bundle, keep @docs Static, static @@ -190,9 +191,12 @@ update config msg model = ( model, Cmd.none ) Link (Browser.Internal url) -> - if url == model.url then + if url == model.url && url.fragment == Nothing then ( model, Cmd.none ) + else if url.path == model.url.path then + ( model, Nav.load (Url.toString url) ) + else ( { model | page = Transition.begin model.page } , Utils.delay config.speed (TransitionTo url) @@ -205,11 +209,7 @@ update config msg model = TransitionTo url -> ( model - , if url.path == model.url.path then - Nav.load (Url.toString url) - - else - Nav.pushUrl model.key (Url.toString url) + , Nav.pushUrl model.key (Url.toString url) ) TransitionComplete ->