Next.js Discord

Discord Forum

App router - refresh props - eg: router.replace(router.asPath) equivalent

Answered
Common Pochard posted this in #help-forum
Open in Discord
Common PochardOP
Looking for appropriate way to refresh server side props, without reloading the entire page.

In pages router, this was done via router.replace(router.asPath), but .asPath is no longer a property of router.

Is it just this?

import { usePathname, useRouter } from 'next/navigation';
//...

const router = useRouter();
const pathname = usePathname();

const refresh = () => router.replace(pathname);


Hoping that's not the case, really dissapointing DX if so.
Answered by Common Pochard
nevermind. its just router.refresh() ! much better than even pages router.
View full answer

1 Reply

Common PochardOP
nevermind. its just router.refresh() ! much better than even pages router.
Answer