remix-run / history

Manage session history with JavaScript
MIT License
8.28k stars 961 forks source link

`parsePath` should match `location` defaults? #897

Closed ryanflorence closed 2 years ago

ryanflorence commented 3 years ago

If the URL is "/some/where"

location.search === ""
let path = parsePath("/some/where");
path.search === undefined;

I think it'd be more useful if the returned path from parsePath looked more like a location.

location.search === ""
let path = parsePath("/some/where");
path.search === "";

Then you can do things like diff the search params of the current URL and some potential next URL.

This would clean up some code over in Remix for <link rel="prefetch"> as well as creating something like <PendingLink />. Today it complicates the comparison with search.

mjackson commented 2 years ago

parsePath is just a parser that tells you what's in the string. It's not designed to give you a full location object. Internally it's used in several places to determine if a string contains e.g. a search or hash component.