Next.js Discord

Discord Forum

How to implement "url auto fix" like Steam has while considering revalidation on Next 12

Unanswered
Devon Rex posted this in #help-forum
Open in Discord
Devon RexOP
Hi,

I am implementing ISR on my website now, and I have a page that behave similar to Steam where

https://store.steampowered.com/app/413150/Stardew_Valley/

if you change Stardew_Valley to anything else it will auto fix it back to Stardew_Valley

I implemented it like so

file nested inside pages folder, inside [id] folder, called [...slug] has
    const router = useRouter();
    const intendedRoute = `/app/${props.gameInfo.id}/${props.gameInfo.slug}`;
    useEffect(() => {
        if (router.isReady && router.asPath !== intendedRoute) {
            router.replace(intendedRoute, intendedRoute, { shallow: true })
        }
    }, [intendedRoute, router, router.isReady]);

Now for revalidate I do res.revalidate(path);

Now technically passing path as app/1234/fake-name will work and won't throw error.

The question is, will it also cover the app/1234/real-name case?

0 Replies