# Noob question: Models getting wiped in between pushUrl calls

**URL:** <https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392>\
**Category:** Learn\
**Created:** [August 13, 2025, 12:20am UTC](https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392 "2025-08-13T00:20:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Davis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/phillip_davis/32/5493_2.png) [@Phillip\_Davis](https://discourse.elm-lang.org/u/Phillip_Davis)\
**Post date:** [August 13, 2025, 12:20am UTC](https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392/1 "2025-08-13T00:20:19Z")

</div>

What the title says, I’m writing an SPA with `Browser.application` (basically just the frontend rn, don’t judge me lol). I have buttons like this:

`button [onClick SubmitInfo] [text "Submit"]`

where `SubmitInfo` is a `Msg` variant (incidentally, it’s not really clear to me how the Msg type matches the interface described by `onClick`).

Here’s the relevant update code:

```auto
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    SubmitInfo ->
      submitInfo model

```

And finally:

```auto
pushUrl : Model -> String -> ( Model, Cmd Msg )
pushUrl model url =
    ( model, Nav.pushUrl model.key url )

submitInfo : Model -> ( Model, Cmd Msg )
submitInfo model =
    pushUrl { model | loginStatus = LoggedIn } (Url.Builder.absolute ["agreement"] [])

```

Every time I push a button like this, the page loads correctly but the `Model` is empty again, as if the HTML has loaded from scratch again.

---

<div class="post-metadata">

**Author:** ![lydell](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lydell/32/178_2.png) [@lydell](https://discourse.elm-lang.org/u/lydell)\
**Post date:** [August 13, 2025, 5:31am UTC](https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392/2 "2025-08-13T05:31:20Z")

</div>

Hi! Is your button inside a `<form>` element by any chance? If so, you are experiencing how forms work by default in browsers. Buttons have a [type](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#type) attribute and it defaults to `"submit"`, which submits the form its in, which results in a full page reload. You can solve it by adding `Html.Attributes.type_ "button"`.

---

<div class="post-metadata">

**Author:** ![Phillip\_Davis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/phillip_davis/32/5493_2.png) [@Phillip\_Davis](https://discourse.elm-lang.org/u/Phillip_Davis)\
**Post date:** [August 13, 2025, 12:14pm UTC](https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392/3 "2025-08-13T12:14:15Z")

</div>

Oh goodness. I don’t do much frontend work, so I’m embarrassed to say I’ve forgotten this behavior of `<form>` and `<button>` and gotten stuck on this bug a couple times before lol. Thanks for the pointer, that did the trick. Go Elm!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [August 23, 2025, 12:14pm UTC](https://discourse.elm-lang.org/t/noob-question-models-getting-wiped-in-between-pushurl-calls/10392/4 "2025-08-23T12:14:31Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
