1

I have a page that's only job is to point to other pages. It's a list of links to other posts and the other posts are static and known entirely at time of deployment.

At the end of the day structure for all the pages I'm creating will resemble this:

[country]/[state]/[city]

I'm assuming I'm the the first who has wanted to something like this... How can I do this?

I've tried using the getStaticPaths and getStaticProps in the index.js file but that's not allowed so maybe there's a way to chain the creation of these directories?


Just for a little bit more context, the way the structure currently works is like this

Canada
  |---- Quebec
  |       |---- Montreal
  |---- Ontario
  |       |---- Toronto
 US
  |---- North Carolina
  |       |---- Charlotte
  |---- Florida
          |---- Orlando

I want to make an index.js page that can build something that looks like this

     Canada
------------------------
     - [Quebec](Montreal)
     - [Ontario](Toronto)

And

     US
-----------------------
    - North Carolina
    - Florida

The city pages (Montreal, Toronto, Charlotte, Orlando) are generated at build time but the list of states isn't generated until the page is requested which makes the website slower than it needs to be (it can be entirely static and Next.js seems like a good tool for automating generating all these pages)

financial_physician
  • 1,672
  • 1
  • 14
  • 34
  • I believe you can use `getStaticProps / getStaticPaths` here. In your `[city].js` you can then generate all paths during build time. Have you checked "Multiple dynamic route segments” in https://nextjs.org/docs/routing/dynamic-routes? – Jirka Svoboda Jul 10 '21 at 12:43
  • Does this help answer your question: [How to generate static pages with nested dynamic routes](https://stackoverflow.com/a/65553115/1870780)? – juliomalves Jul 11 '21 at 11:03
  • I realize I sorta asked about dynamic routing but I was trying to focus more on loading static assets into a next js page.... I think I'll delete this question and re-ask more clearly. Sorry – financial_physician Jul 12 '21 at 00:29

0 Answers0