Skip to content

$page.url.hash is not updated. #9374

@hyunbinseo

Description

@hyunbinseo

Describe the bug

When the URL hash value is changed using the address bar, the $page store is not updated.

Reproduction

Checked on Chrome, Firefox, and Safari. Reference 'System Info' for version numbers.

<script>
  import { page } from '$app/stores';
  
  $: console.log($page.url.hash);
</script>

<svelte:window
  on:hashchange={() => {
    console.log($page.url.hash, 'store');
    console.log(window.location.hash, 'location')
  }}
/>

<a href="#1">#1</a>
  1. Load the page
  2. Click the anchor element.
  3. Replace #1 with #2 in the address bar.
  4. Check the console.
<!-- Anchor is clicked. Hash is now #1 -->
#1
#1 store
#1 location

<!-- URL is updated. Hash is now #2 -->
#1 store
#2 location

Logs

No response

System Info

System:
  OS: macOS 13.2.1
  CPU: (8) arm64 Apple M1
  Memory: 78.86 MB / 8.00 GB
  Shell: 5.8.1 - /bin/zsh
Binaries:
  Node: 18.14.1 - ~/.nvm/versions/node/v18.14.1/bin/node
  npm: 9.3.1 - ~/.nvm/versions/node/v18.14.1/bin/npm
Browsers:
  Chrome: 110.0.5481.177
  Firefox: 110.0
  Safari: 16.3
npmPackages:
  @sveltejs/adapter-auto: ^2.0.0 => 2.0.0 
  @sveltejs/kit: ^1.5.0 => 1.11.0 
  svelte: ^3.54.0 => 3.55.1 
  vite: ^4.0.0 => 4.1.4

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions