<NuxtChild /> is reloading parent page in Nuxt 3.
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v16.14.2
- Nuxt Version:
3.0.0-rc.3
- Package Manager:
npm@8.5.0
- Builder:
vite
- User Config:
runtimeConfig
,typescript
,modules
,tailwindcss
- Runtime Modules:
@nuxtjs/supabase@0.1.16
,@nuxtjs/tailwindcss@5.1.2
- Build Modules:
-
Reproduction
https://codesandbox.io/s/nuxt-3-child-routes-ony35p?file=/pages/index.vue
Describe the bug
<NuxtChild />
routes should not reload the parent page and lose state.
If I navigate to child 1 or child 2, the parent index page is re-rendered / loaded when it should simply load in the child and maintain its state. I believe this is the behaviour in Nuxt 2.
I have a reproduction link above but even on CodeSandbox, the script is not working for some reason. It’s not 100% needed to demonstrate the bug but would make the reloading issue more apparent as the count gets reset back to zero on each navigation within the parent index (this same code works locally but there appears to be an issue on CodeSandbox regarding this).
Additional context
This could be a bug or it could be a misunderstanding with how routes and layouts now work in Nuxt 3. Unfortunately the documentation in Nuxt 3 regarding routing is very minimal so I’m not able to see if it’s this way by design and instead some misconfiguration on my part.
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
The issue was that
<NuxtLayout>
was the root element of your page. It needs to be wrapped in another element. We could possibly add a comment about that in the docs.Here’s your repro, with only that change made: https://github-tlz3zz--3000.local-corp.webcontainer.io/child-2
~> https://github.com/nuxt/framework/pull/5345