I’d like to create a simple page in my Next.js app that lists all the routes defined in the XDN router. Is that possible?
Can you elaborate on what you’re trying to do and why?
Unofficially, there is a representation of the routes in a project in the
xdn.json file in the
.xdn directory of your project that’s created at build time but that format is subject to change and should not be relied on.
I wanted a page that we’d use internally that lists out all the URLs I’ve defined for the site. Not sure if there’s a general use case for this. It’s like the original use of the
index file or the canonical blog tutorial where the homepage lists all posts.
Let’s back up a sec and make sure we’re talking about the same thing because I might be misunderstanding what you’re asking.
What I call routes are the patterns that define the types of pages in your app. For example:
What I call paths are all the various page URLs that make up your site. For example, the route
/product/:productid has these as possible paths:
It sounds like you’re asking for the list of URLs (aka paths), correct? While the XDN and Nextjs know the routes in your app, the list of all valid URLs is varied and application dependent. Consider case of the product route above. Only your ecommerce system knows which values for
:productid are valid.
Is your app static or dynamic? For static apps in Nextjs there may already be a list of valid URLs in the
getStaticPaths method that you can use.