I'm building an app where different users can register and get a frontpage. I then assign each user a subdomain (say userA.mydomain.com
) and would like to display the user's frontpage when we access his subdomain.
I already got it working that the different subdomains route to the NextJS app, but now I need to display the user's data on that frontpage. So when we go to userA.mydomain.com
I need to display userA's data.
I know that I can generate the static pages for each user by creating a page under /pages/frontpages/[userId].tsx
, but then the domain would look like this: userA.mydomain.com/frontpages/userA
. This is redundant, because we already know the userId because of the subdomain. Also we can access other user's frontpages from another user's subdomain.
I also know that I can fetch the data inside the index page, but then we loose all benefits of statically generated pages.
My questions are:
Is there a way to get what we would have with
pages/[userId].tsx
but for the index page? I don't want to fetch the data inside the index page itself because then I loose the benefit of statically generated pages. Maybe there's something that we can do withgetStaticPaths
?For example is it possible to prerender the frontpages using
getStaticPaths
forpages/frontpages/[userId].tsx
and then inside the index page we just render the content of the generated frontpage page (based on the subdomain of the url)?