Next.js Discord

Discord Forum

Force remount on link click

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
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?

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 key to force remount?

"use client";
const pathname = usePathname();
<Component key={pathname} />

in the example above, Component is rerendered when pathname changes
Spectacled bearOP
using an <a> tag instead of <Link> works, would forcing the remount be preferable?
depends on if you think using <a> is still good
if you use <a> you lose react-y client side navigation and instead use native browser navigation
which 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