preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.01k stars 156 forks source link

page does not refresh when press browser back button, if hash history is being used #378

Closed xiaodid closed 2 years ago

xiaodid commented 4 years ago

what happed

1, create a default project by using preact-cli. 2, then following the preact-router document to add createHashHistory 3, then build the project, but a error will occur, just like mentioned below:

377

4, after adding those build parameters --no-sw --no-ssr --no-esm --no-inline-css --no-prerender, the build can be done. 5, then run npm run serve to start dev server 6, open localhost:8080, then click Me, then click John 7, click the back button of browser several times. 8, the wrong page will be seen.

preact-router@3.2.1 history@5.0.0 preact@10.4.8 preact-cli@3.0.1

midahp commented 3 years ago

I had the same issue. I changed https://github.com/preactjs/preact-router/blob/master/src/index.js#L188 from: this$1.routeTo(("" + (location.pathname || '') + (location.search || ''))); to: this$1.routeTo(("" + (location.location.pathname || '') + (location.location.search || '')));

This might break other things but works for me.

simbo commented 3 years ago

Same issue here... Browser back+forth doesn't work with hash history using history@5.0.0 with preact@10.5.7 and preact-router@3.2.1.

It works fine with history@4.10.1... 🤷‍♂️

kufii commented 3 years ago

can confirm that using history@4.10.1 fixes it for me