NextJS & Prismic - How to prevent /:uid from rendering homepage

272 views Asked by At

In the prismic docs the default setup they teach means that your homepage and every other page on your site is the same type.

This means that in that default setup the routes / and /home both render the homepage.

Is there a way to prevent the /home route from rendering, or at least redirect it to /?

1

There are 1 answers

0
Sam Littlefair On BEST ANSWER

The easiest way to do this is just with a standard redirect, in your next config:

https://nextjs.org/docs/api-reference/next.config.js/redirects

But there are some other ways that might work, too. For instance, you could add a if(params.uid === "home") router.push("/") to pages/[uid].js, to redirect users from /home to /. (I don't think that code snippet would work, but I hope it illustrates the concept.)

Let me know if you want some other ideas, or if you need help with implementation! I'd be happy to put together a proper example if you need :)

Sam

Edit: Another option would be to create a singleton "Homepage" Custom Type in Prismic.