Replies: 1 comment
-
For some reason, this no longer appears in the "Discussions" list, so I'm commenting here in an attempt to bump. I see no indication that the item was closed or killed, since I can still pull it up (although I had use my browser history to do so). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
(Warning: I've already asked this question in varying forms on both Stack Overflow and the Reddit Next.js subreddit and, while the answers gave good information, I still need help. If this makes my question irrelevant, I understand.)
Can anyone offer a Next.js beginner any pointers on using
getStaticPaths
andgetStaticProps
with catch-all routes? Most Next.js 9.3+ blog starters seem to be based on just one level of blog posts (e.g.,/posts/post-1.md
,/posts/post-2.md
, etc.), but what I've tried vainly to find is a starter — or just a set of instructions — that addresses handling, say,/posts/yyyy/mm/postname.md
through/pages/posts/[...post].js
.I tried using
fs-readdir-recursive
to read the/posts/
directory's various levels and that works, but what it gives me doesn't produce something thatgetStaticPaths
likes. I'm sure I just need to massage the result but can't find any examples to help me figure it out.(Most examples that do go further than the one-level scenario seem to deal with fetching from DBs, perhaps because the scenario I'm trying to find is considered too simple. Probably is, for non-beginners, but...)
The code I tried initially failed because, as I was told on Reddit, it was providing
getStaticPaths
apaths
constant which was an array of strings, not an array of objects. I then reworked it accordingly......but could find nothing in the docs or any related articles that showed me where to go from there, since my own attempts to make the array "useful" to the rest of the code were unsuccessful.
Would tremendously appreciate any tips on these items. Thanks — and sorry to all for what I'm sure is a dumb question! Just trying to understand.
Beta Was this translation helpful? Give feedback.
All reactions