Open zth opened 2 years ago
I'm starting to think we should have a useRoute
instead of just a useQueryParams
, with a setParams
that covers setting both query params and path params. We do want the developer to think less in terms of path params vs query params, and more in terms of just "params for my route".
I'd be interested to see how such an API would look.
For me personally there is a clear distinction between "path params" and "query params".
Path parameters are specifically for a resource e.g.
topics
- a topic overviewtopics/:topicId
- A specific topictopics/:topicId/contributers
- Details of a specific topicAs you can see, for me path parameters always have a clear hierarchy (and I would say that in a good URL structure I should be able to remove any path "part" and still arrive on an existing page).
In contrast query parameters are used for specific state on a page (e.g. pagination):
topics?at=:cursor&direction=forward
- paginationtopics/:topicId?shared-via=button
- metadata of how the page was shared
It's currently easy to change query parameters, but it'd be cool to have something that allows updating path parameters easily as well.
An example use case: Imagine you have a backoffice where you can navigate to different pages to administer organizations. The organization slug is a path parameter in the URL. The page also has a search bar at the top, where you can search for organizations and move to their backoffice.
Now, imagine you want to stay at the current page when searching in that bar, just switch out what org you're looking at. This is pretty painful to do today. But, if we have something like
Routes.Backoffice.Dashboard.updatePathParams(~slug=newSlug)
then that would be very easy instead.cc @Kingdutch , what do you think?