1
0
mirror of synced 2025-12-30 03:01:36 -05:00

keep language prefix when doing client-side refresh (#31686)

Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com>
This commit is contained in:
Peter Bengtsson
2022-10-17 14:35:51 +02:00
committed by GitHub
parent bf4873c87b
commit 2e957dbd91

View File

@@ -11,7 +11,11 @@ export default function ClientSideRefresh() {
useSWR(
router.asPath,
() => {
router.replace(router.asPath, undefined, { scroll: false })
// Remember, in NextJS, the `router.locale` is never including the
// `router.asPath`. So we have to make sure it's always there
// otherwise, after this hook runs, you lose that `/en` prefix
// in the URL on the address bar.
router.replace(`/${router.locale}${router.asPath}`, undefined, { scroll: false })
},
{
// Implied here is that `revalidateOnFocus: true` which the default