Next.js Discord

Discord Forum

Best place to scan all routes?

Unanswered
Colombian fino hound posted this in #help-forum
Open in Discord
Colombian fino houndOP
Where would be the best place, to scan for all availiable routes, by extending the metadata object within a page.tsx with a custom navigation object?

My idea is to build the navigation dynamically based on an object is exported within the metadata object:

/app/statistics/page.tsx
export const metadata: CustomMetadata = {
  title: 'Stats',
  navigation: {
    name: 'Stats',
    url: '/statistics',
    icon: 'stats'
  },
};

I want this to work dynamically as I add pages, but not on every render. (Yes, the dynamic routes will be treated otherwise)

1 Reply

Colombian fino houndOP
Bumping this with a more specific explanation:

I would like to extend Next.js's metadata:
export const metadata: Metadata = {
  title: 'Insights'
};

by being able to add:
export const metadata: CustomMetadata = {
  title: 'Insights',
  navigation: {
    name: 'Insights',
    url: '/insights',
  },
};

And then "scan" all page.tsx in routes for a metadata object that has a "navigation" key, in order to build a top menu dynamically without needing a .json or similar in the root.

Where would you place such a parser/scanner, which also works in HMR (Hot Module Replacement)?