Skip to content

router.push replaces history #2457

@adjsky

Description

@adjsky

Inertia adapter(s) affected

  • React
  • Vue 3
  • Svelte
  • Not Applicable

JS package version

2.0.17

Backend stack (optional)

No response

Describe the problem

router.push does not push a new history entry; instead, it replaces it if the provided url is identical to the previous one (even if it includes a hash).

As i see from the code, this behavior is intentional.

replace = replace || isSameUrlWithoutHash(hrefToUrl(page.url), location)

I would like to know what this check is for, since the fact that push actually replaces the history state is very misleading and this behavior is not documented.

Steps to reproduce

<script>
    import { router } from '@inertiajs/svelte';
</script>

<button onclick={() => router.push({ url: '' })}>push (empty)</button>
<button onclick={() => router.push({ url: '#bogus' })}>push (hash)</button>
<button onclick={() => router.push({ url: '?bogus' })}>push (query)</button>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions