I have a form which puts to URL "/search/?q=my searching query..". How to get this my searching query.. as params?
How to get the my "searching query.." as params? When I try by useParams it doesnt work because of "?" symbol.
Of course I can do it without that action="/search/" on my input but I see it more true way to do searching.
CodePudding user response:
You've defined ":query" as url parameter, but "?q=my searching query.." is a search query. You could get it like:
const { search } = useLocation();
const searchParams = new URLSearchParams(search);
const searchQuery = searchParams.get('q')
And you could also remove the ":query" from route path.