mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
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 <[email protected]>
36 lines
855 B
JavaScript
36 lines
855 B
JavaScript
import { useRouter } from 'next/router'
|
|
import { useEffect, useState } from 'react'
|
|
import Debug from './debug'
|
|
|
|
function transform(router) {
|
|
return {
|
|
pathname: router.pathname,
|
|
asPath: router.asPath,
|
|
query: Object.entries(router.query)
|
|
.map(([key, value]) => [key, value].join('='))
|
|
.join('&'),
|
|
isReady: router.isReady ? 'true' : 'false',
|
|
}
|
|
}
|
|
|
|
export default function DebugError({ children }) {
|
|
const router = useRouter()
|
|
const [debug, setDebug] = useState({})
|
|
|
|
useEffect(() => {
|
|
setDebug(transform(router))
|
|
}, [router])
|
|
|
|
return (
|
|
<>
|
|
<dl>
|
|
<Debug name="pathname" value={debug.pathname} />
|
|
<Debug name="asPath" value={debug.asPath} />
|
|
<Debug name="query" value={debug.query} />
|
|
<Debug name="isReady" value={debug.isReady} />
|
|
</dl>
|
|
{children}
|
|
</>
|
|
)
|
|
}
|