Previously, query parameters were not available on 404 pages because
calling the router methods would change the pathname in the browser.
This change adds support for the query to update for those pages without
updating the path to include the basePath.
This additionally narrows some Typescript types that were previous set
to `any` which highlighted some type errors that were corrected.
Fixes: https://github.com/vercel/next.js/issues/35990
Co-authored-by: JJ Kasper <jj@jjsweb.site>