Skip to content

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

@evanbattaglia

Description

@evanbattaglia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions