nextra icon indicating copy to clipboard operation
nextra copied to clipboard

How to correctly handle `_meta` files for dynamic routes?

Open zevnda opened this issue 2 months ago • 3 comments

I could very well just be missing something obvious, but I can't seem to get _meta files to work for dynamic routes.

When doing the following, I would expect the nabvar to be hidden on all routes within dynamic-route/ only; however, it is affecting every route instead, including the dynamic routes

dynamic-route/
├── _meta.ts
└── [slug]/
    └── page.tsx
// _meta.ts
export default {
  '*': {
    type: 'page',
    theme: {
      navbar: false,
    },
  },
}

Trying a global approach with a combination of attempts just gives me errors

app/
├── _meta.global.ts
├── layout.tsx
└── dynamic-route/
    └── [slug]/
        └── page.tsx
// _meta.global.ts
export default {
  // ... other routes working fine
  'dynamic-route': {
    type: 'page',
    theme: {
      navbar: false,
    },
  },
}
// _meta.global.ts
export default {
  // ... other routes working fine
  '[slug]': {
    type: 'page',
    theme: {
      navbar: false,
    },
  },
}

and a few more..

Error: Validation of "_meta" file has failed.
The field key "dynamic-route" in `_meta` file refers to a page that cannot be found, remove this key from "_meta" file.

Error: Validation of "_meta" file has failed.
The field key "[slug]" in `_meta` file refers to a page that cannot be found, remove this key from "_meta" file.

At this point, I'm stumped on how to handle this correctly, so any help would be appreciated.

zevnda avatar Oct 04 '25 12:10 zevnda

Adding a page.tsx file to dynamic-route/ with the following in _meta.global seems to get rid of the Validation of "_meta" file has failed. error, but still none of the properties are applied to those routes.

// _meta.global.ts
export default {
  'dynamic-route': {
    items: {
      '*': {
        type: 'page',
        theme: {
          navbar: false,
        },
      },
    },
  },
}

zevnda avatar Oct 04 '25 13:10 zevnda

It appears my only option is to set the navbar: bool property on all other routes that aren't dynamic, and then use the '*' key/fallback to target just the dynamic routes. The issue here is that I will likely want the navbar visible on some dynamic routes, and not on others, but that wouldn't be possible.

zevnda avatar Oct 04 '25 13:10 zevnda

Hi, dynamic pages aren't added in pageMap ref https://github.com/shuding/nextra/issues/3768#issuecomment-2520402747

for now you need to manually enhance pageMap take a look at nextra.site https://github.com/shuding/nextra/blob/main/docs/components/get-page-map.ts

this DX I want to improve in Nextra 5

dimaMachina avatar Oct 06 '25 11:10 dimaMachina