page.js
page.js copied to clipboard
Incorrect pathname and querystring
When you click on a bookmark of a page with a query-string, context has incorrect pathname and querystring.
Example:
Page URL is http://domain.com/products/?id=10 which includes the following link:
<a href="#bookmark">link</a>
When clicked, URL is:
http://domain.com/products/?id=10#bookmark
At this point,
window.location returns:
{
hash: "#bookmark",
search: "?id=10",
pathname: "/products/",
href: "http://domain.com/products/?id=10#bookmark",
...
}
but
page.js context returns:
{
hash: "bookmark",
querystring: "", // should be "id=10"
pathname: "/products/#bookmark", // ?
path: "/",
...
}
Page.js version 1.7.1 Chrome version 50.0.2661.102
What does your use of page() look like here? What route are you listening to?
@matthewp It's simple:
page('(/)?products', (context, next) => {
console.log(context);
});
page('(/)?', (context, next) => {
console.log(context);
});
Thanks! I'll try to take a look.
Leaving this info here if someone musters the energy to send a PR
Pathname is set to URL without string content after ?.
https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.mjs#L1084
But when hasbang is false and URL has a hash, pathname and path are set to the initial full path. https://github.com/visionmedia/page.js/blob/4f9991658f9b9e3de9b6059bade93693af24d6bd/page.mjs#L1089-L1092
Soo navigating to a URL that has an hash and a question mark will cause wrong pathnames.
http://example.com/products/?id=1#bookmark