NuxtN
Nuxt12mo ago
Mike Chao

pages onMounted hook being called twice when switching layouts in app.vue

Hello everyone,
I am working on my first web app using Nuxt 3. In my app.vue I am using a computed property to determine the layout that will be bound to NuxtPage name property.

I discovered that when I navigate from 1 page using default layout to another page using custom layout the onMounted hook is called twice.

I made a simple reproduction here: https://stackblitz.com/~/github.com/mikechao/mount-twice
Open the include browser in a separate tab, open the console and click the 'To custom' link

Is this the expected behavior? Or am I doing something incorrectly?

nuxi info output:
Nuxt project info: 10:28:45 AM

------------------------------
  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.15.0
  • CLI Version: 3.17.2
  • Nitro Version: -
  • Package Manager: pnpm@8.15.6
  • Builder: -
  • User Config: default
  • Runtime Modules: -
  • Build Modules: -
    ------------------------------
    Thanks
image.png
Was this page helpful?