Next.js Discord

Discord Forum

Getting URL/Search Parameters From Client

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
I am trying to get URL params using either useSearchParams from next/navigation or router.query from next/router but I am having issues with getting the params that are loaded client side.

I have a getStaticProps page that has a search grid on it. The search grid uses URL parameters to handle faceting/sorting/pagination. Since the page is loaded via getStaticProps, URL parameters are not supported at load time. That's all well and good so far, but if I try to look at the params returned from the router, or from useSearchParams, there is the initial set which are the params returned from the supported params from the page itself. In this case the page is under the directory /member/{slug} so when the page first loads the params from the URL are {slug: foo} and then if there are any other URL params, they will show on the client so your order of url params can be

1) {slug: foo}
2) {slug: foo, sort: price}

My issue is that I want to know if certain URL parameters are present (or not) before making the initial search request. As it stands now, the search grid itself has support to be hydrated from a server response, or from a client response, but in this case of a client response, it will make a request with params #1, and then with #2.

My question is how can I tell if the URL params have been fully loaded from the client before deciding to handle them?

1 Reply

Northeast Congo LionOP
GPT help Discord channel to the rescue. router has a isReady method on it that was just what I was looking for!