I have an Express application that gets search parameters and page numbers via query strings.
var name = req.query.name;
var state = req.query.state;
var category = req.query.category;
var pageNum = req.query.pagenum;
What I want is if the search query has a page number and yields no results, to do a search without the page number and pass that back to the client. This works fine, and the front-end is receiving the data correctly.
The only thing is that I want the URL to reflect the changed page number search, so rather than being website.com/search?page=4&state=AL
I'd like it to have the page number stripped or changed to 1. I can do this via Javascript on the front-end, but I'd rather have the url changed on the server side (it makes more sense to me at least, rather than having to change every template to do that).
EDIT:
Looks like the only way of doing this is to redirect to the URL without the page query string parameter. It seems this will help me out in getting this done.