visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Relative link when current location has #hash triggers a reload while it doesn't with no #hash or empty # #579

Open dmnsgn opened 3 years ago

dmnsgn commented 3 years ago

Setup

Two routes will render different pages:

page('/fruits', () => {})
page('/veggies', () => {})
page('/fruits/:name', () => {})
page('/veggies/:name', () => {})
page()

Problem

If on page /fruits/banana#calories you click on a link href "/veggies/tomato" (no other attribute), the page will reload. No problem with either /fruits/banana# or /fruits/banana. Sounds like an issue with handling hash?

dmnsgn commented 3 years ago

Could it be that the /fruits#calories hashtag part is unhandled by my defined route above?

I am hitting the following infinite loop when clicking on an anchor that changes the hastag.

Uncaught RangeError: Maximum call stack size exceeded.
    at Page.unhandled (page.js:1056)
    at nextEnter (page.js:712)
    at eval (page.js:1183)
    at nextEnter (page.js:713)
    at eval (page.js:1183)
    at nextEnter (page.js:713)
    at eval (page.js:1183)
    at nextEnter (page.js:713)
    at eval (page.js:1183)
    at nextEnter (page.js:713)

And also the following line is only taking into account window.location.search and not window.location.hash? https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/index.js#L643

rkyoku commented 2 years ago

If you are calling page.stop() and page.start(), it may be because there is a bug in page.start() that doesn't set this._running = true; if you specified {dispatch: false}

Please see lines 551 and 552 of page.js.

Line 552 should have been put before line 551, or at the very least there should have been a way to set it to true.

I had to modify page.js for my website to work properly, but fortunately it was easy to modify.

AshfordN commented 1 year ago

I'm not sure I exactly understand your problem, but perhaps you can look at this answer and see if it applies.