visionmedia / page.js

Micro client-side router inspired by the Express router

Home Page:http://visionmedia.github.com/page.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

evanbattaglia opened this issue · comments

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():

page.js/page.js

Line 1090 in 4f99916

this.pathname = _page._decodeURLEncodedURIComponent(~i ? path.slice(0, i) : path);

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

page.js/page.js

Line 1098 in 4f99916

this.path = this.pathname = parts[0];

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).