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

Whether pathname includes base depends on whether there is an anchor (#foo) #589

Open evanbattaglia opened 2 years ago

evanbattaglia commented 2 years ago

I apologize if I missed an existing issue for this, or if this is expected behavior, but it seems surprising to me. #575 is similar but this is specifically around pathname and base URL. Assuming hashbang is false, if there is no hash symbol (anchor) in the document URL, the pathname is based on path so includes the base URL. In Context():

https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L1090

However, if there is a hash symbol (anchor), pathname depends on this.path, which does not have the base URL.

https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.js#L1098

I came across while tracking a bug in our code. Here is a gist which shows the behavior in isolation.

https://gist.github.com/evanbattaglia/2b76bf11fe8a18ac4dcef14f2138a2cc

URL: /index -> pathname /basic/ URL: /index#whoop -> pathname / URL: /basic/about -> pathname /basic/about URL: /basic/about#whoop -> pathname /about

The documentation states pathname is The pathname void of query string "/login"., which implies it should not have the base URL (/admin in the documentation).