How to get an array of the static pages in the app?
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
Is there a canonical way to get all the urls in a nextjs app? I realize that I'll have to come up with a solution for [slug] pages (i.e. call 'getStaticPaths' to get the dynamically generated paths) but is it possible to get an array of the "normal" pages that have their own js files under the /pages folder? I'm creating a custom sitemap if that helps.
5 Replies
@Masai Lion Is there a canonical way to get all the urls in a nextjs app? I realize that I'll have to come up with a solution for [slug] pages (i.e. call 'getStaticPaths' to get the dynamically generated paths) but is it possible to get an array of the "normal" pages that have their own js files under the /pages folder? I'm creating a custom sitemap if that helps.
Built in way then afaik there is none, but you can do that easily with fs
For sitemap though there are specialised toolings for that
Like this one https://www.npmjs.com/package/next-sitemap
Masai LionOP
sweet - thanks. I'm switching to using the filessytem directly. When I parse the pages directory, do you know how I could call
getStaticPaths on the files I find?@Masai Lion sweet - thanks. I'm switching to using the filessytem directly. When I parse the pages directory, do you know how I could call `getStaticPaths` on the files I find?
Well just import fs to getStaticPaths and run it there