Skip to content

Warn in dev mode if nested route without <NuxtPage /> exists #25077

Closed

Description

@TheRoccoB

Environment

  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.9.1
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: npm@10.2.5
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-issues-25077?file=pages%2Findex.vue

npx nuxi@latest init nuxt_routing
cd nuxt_routing
npm run dev

setup app.vue for router by adding NuxtPage

<template>
  <div>
    <NuxtPage />
  </div>
</template>

Setup pages directory like this:

pages
├── [username]
│   └── [page].vue
├── [username].vue
└── index.vue

Here it is attached as zip:
pages.zip

localhost:3000 (correct)
image

localhost:3000/myUser (correct)
image

localhost:3000/myUser/myPage (incorrect)
image

It is showing [username].vue. I expect it to be showing [page].vue like this
image

It does work if I delete [username].vue.

Describe the bug

A nested directory structure like this

pages
├── [username]
│   └── [page].vue
├── [username].vue
└── index.vue

Fails to render localhost:3000/myUser/myPage as [page].vue. It renders [username.vue].

I RTFM, and I'm pretty sure this is how to set it up, but if I got it wrong please let me know.

Thanks!

Additional context

No response

Logs

No response

Activity

  1. TheRoccoB commented on Jan 6, 2024

    @TheRoccoB
    Author

    oh, I did just find a workaround. renaming [username].vue to [...slug.vue] and changing the code a bit works for all the URL's I showed in the repro case:

    image

    But even with that workaround, http://localhost:3000/myUser/myPage/abcd goes to [...slug.vue] which I don't really want. In that case I want 404. I guess I could just throw a 404 if slug is too long, but this still seems wrong.

  2. TheRoccoB commented on Jan 6, 2024

    @TheRoccoB
    Author

    OK this new directory structure actually works in all cases:

    image

    It still seems though that my original attempt should either throw an error telling you what to do (or work).

    Guess I needed to talk to the duck.

  3. TheAlexLichter commented on Jan 6, 2024

    @TheAlexLichter
    Member

    I think you accidentally created a nested route. @danielroe do you think we should warn if a nested route without <NuxtPage> exists or do you have valid use cases of that in mind? 🤔

    Repro: https://stackblitz.com/edit/nuxt-issues-25077?file=pages%2Findex.vue

  4. bolt-new-by-stackblitz commented on Jan 6, 2024

    @bolt-new-by-stackblitz
  5. danielroe commented on Jan 6, 2024

    @danielroe
    Member

    I think that would be a nice DX improvement. 👌

  6. changed the title [-]Nested Dynamic Routes working improperly[/-] [+]Warn if nested route without `<NuxtPage />` exists[/+] on Jan 6, 2024
  7. changed the title [-]Warn if nested route without `<NuxtPage />` exists[/-] [+]Warn in dev mode if nested route without `<NuxtPage />` exists[/+] on Jan 7, 2024
  8. saidinusah commented on Jan 11, 2024

    @saidinusah

    hi, is anyone working on this? I'd love to work on it

  9. TheAlexLichter commented on Jan 11, 2024

    @TheAlexLichter
    Member

    @1nusah go for it 👍

  10. saidinusah commented on Jan 11, 2024

    @saidinusah

    heyy @manniL, is there a way to know if the parent route (same thing as the base route?) doesn't have the component? I'm looking at checking if a route has children and if it has the NuxtPage component. What do you think of this approach?

  11. TheAlexLichter commented on Jan 11, 2024

    @TheAlexLichter
    Member

    @1nusah maybe you could use a similar approach as for <NuxtLayout> - see #24116

  12. saidinusah commented on Jan 15, 2024

    @saidinusah

    hi @manniL, I thought the best approach was to show devs when a route has children but the component isn't used in the base route/path but this won't work if you use the component in the app.vue file as it automatically works as if all other routes use this component. Another approach may be to just check if the user has multiple routes and doesn't use the component but this doesn't seem to greatly improve DX in any way to me. What do you think?

  13. added 2 commits that reference this issue on Jul 18, 2026
    1dfb1f5
    7ed3621
  14. Jorgagu commented on Jul 18, 2026

    @Jorgagu
    Contributor

    @TheAlexLichter @danielroe this issue will be resolved by #35639, could you please review ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions