Search parameters
Edit this pageSearch parameters are used to pass data to a route using the query string.
The query string is the part of the URL that comes after the ?
character and is used to pass key-value pairs to the route.
In Solid Router, these query parameters can be accessed using useSearchParams
.
This primitive retrieves a tuple that contains a reactive object that reads the current search parameters and a function to update them.
The getter, in this case searchParams
, is used to read the current search parameters.
setSearchParams
works as the setter which accepts an object whose entries will be merged into the current query.
Multiple queries
Since setSearchParams
accepts an object, you can pass multiple key-value pairs to update multiple search parameters at once.
If the value of a search parameter's key is undefined
, null
, or an empty
string (""
), it will be removed from the query string.
Accessing query strings
If you require accessing the query string directly, you can use the useLocation
primitive:
If the URL was http://localhost:3000/users?username=john&page=1
, the output would be Query String: ?username=john&page=1
.