QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

[🐞] `prevUrl` of the `useLocation()` is set even if the first view. #6625

Open genki opened 4 months ago

genki commented 4 months ago

Which component is affected?

Qwik City (routing)

Describe the bug

I have tried to detect the SPA navigation. I expected the loc.prefUrl is undefined at the first render, but it is already set to the URL of the page at the very beginning.

Reproduction

https://stackblitz.com/edit/qwik-starter-q5hnsb?file=src%2Froutes%2Findex.tsx

Steps to reproduce

No response

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 93.28 MB / 24.00 GB
    Shell: 3.6.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.12.1 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.5.0 - /opt/homebrew/opt/node@20/bin/npm
    pnpm: 9.3.0 - ~/Library/pnpm/pnpm
    bun: 1.1.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    @builder.io/partytown: ^0.10.0 => 0.10.2 
    @builder.io/qwik: workspace:^ => 1.5.6 
    @builder.io/qwik-city: workspace:^ => 1.5.6 
    typescript: 5.4.5 => 5.4.5 
    undici: * => 6.6.2 
    vite: ^5.2.10 => 5.2.11

Additional Information

No response

gnemanja commented 2 months ago

This is why the documentation example doesn't work: https://qwik.dev/docs/api/#going-back

wmertens commented 2 months ago

Good point, PR welcome. The code is most likely inside qwik-city-component.tsx

PatrickJS commented 2 months ago

you can use nav(-1) to go back.

the value might be set here https://github.com/QwikDev/qwik/blob/551e9fe950a469528845c43888899f1f089675d5/packages/qwik-city/src/runtime/src/qwik-city-component.tsx#L224 so PRs welcomed