I create this topic to discuss how this API should be.
To start with it, this package should
- allow you to change the URL easily using a link or a pathname
- change the URL in the state and in the browser’s address bar at the same time
- allow pagination (i.e. URLs like
https://my.site/category/example/page/2
) - listen to changes in the browsing history and update the state
State
It was mentioned in other posts to use something like the following:
-
url
: the full URL (to be used in the address bar and by analytics extensions)- it can be a derived prop of the next two.
-
path
just the pathname of the URL (without the page) -
page
: the page number
Actions
-
set({ path, page })
I’m not sure which would be the best arguments to pass to this action
Effects
- Some functions to handle
window.location
andwindow.history
APIs, and a listener for thepopstate
event.