qwik icon indicating copy to clipboard operation
qwik copied to clipboard

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

Open genki opened this issue 1 year ago • 3 comments

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

genki avatar Jul 01 '24 00:07 genki

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

gnemanja avatar Sep 13 '24 15:09 gnemanja

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

wmertens avatar Sep 14 '24 09:09 wmertens

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

PatrickJS avatar Sep 14 '24 15:09 PatrickJS

I added this <a href="/user"> to go in a different page and in that page prevUrl.href is http://localhost:5173/user/ That's so weird :eyes:

gioboa avatar Nov 21 '24 16:11 gioboa