Force remount on link click
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hi,
When navigating between product pages in my next.js site, some constants like selectedVariant that I use on the page are not unmounting and remounting causing client side errors when that variant can't be found.
Is there a known way to force a full page load?
When navigating between product pages in my next.js site, some constants like selectedVariant that I use on the page are not unmounting and remounting causing client side errors when that variant can't be found.
Is there a known way to force a full page load?
7 Replies
@Spectacled bear Hi,
When navigating between product pages in my next.js site, some constants like selectedVariant that I use on the page are not unmounting and remounting causing client side errors when that variant can't be found.
Is there a known way to force a full page load?
maybe try using react
in the example above,
key to force remount?"use client";
const pathname = usePathname();
<Component key={pathname} />in the example above,
Component is rerendered when pathname changesSpectacled bearOP
using an <a> tag instead of <Link> works, would forcing the remount be preferable?
depends on if you think using
<a> is still goodif you use
<a> you lose react-y client side navigation and instead use native browser navigationwhich can be a bad thing for some people
but if you are okay with it, it's a good simple soltuion
Spectacled bearOP
great, thanks for your help