cid
cid

Reputation: 467

Can getStaticPaths accept dynamic slug(s)?

In a file called pages/posts/[...slugs].tsx I have the getStaticPaths function defined like this:

export async function getStaticPaths() {
  return {
    paths: [
      { params: { slugs: ['1', 'hunt-for-the-hidden-reindeer'] } },
      { params: { slugs: ['1'] } },
    ],
    fallback: false
  };
}

How can I make the paths take in just { params: { slugs: ['1'] } } and accept any other subsequent slugs that may come in. For example, serve the same static site for /1, /1/hello, and 1/random using one rule. Is that possible?

Upvotes: 0

Views: 281

Answers (1)

Mehmet Pekcan
Mehmet Pekcan

Reputation: 288

Your question is not so clean. If you want to render the same page for some rule base URLs you can use rewrites. But if you want to create a static page for some slugs within an array, there is no such thing that will generate. To achieve rendering same page for all slug: /1, slug: /1/hello, slug: /1/random etc. You should implicitly write in every element of paths array.

Upvotes: 1

Related Questions