Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
How do I render a standalone component on NUXT 2 which doesn't destroy on route change

Usually in vue 2, you render a component that doesn't close on route change, you include it directly in your app.vu file. How do I achieve this in nuxt 2.

I am trying to implement a chat module and don't want to include the component on every instance it is needed (That will mean new socket connection on every route)

Is there a workaround?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Put that in your default layout, it should be enough.
More info here: https://nuxtjs.org/docs/concepts/views/#default-layout

Something like this in /layouts/default.vue

<template>
  <div>
    <nav>
      <ul>
        <li>
          <NuxtLink to="/">Home</NuxtLink>
        </li>
        <li>
          <NuxtLink to="/parent">Parent</NuxtLink>
        </li>
      </ul>
    </nav>
    <main>
      <img src="~/assets/logo.svg" />
      <Nuxt />
    </main>
  </div>
</template>

And a simple page should do it

<template>
  <div>
    <h1>Hello Nuxters! ๐Ÿ‘‹</h1>
  </div>
</template>

No need to define a specific layout here since default is the one used by default.

Codesandbox example available here: https://nuxtjs.org/examples/routing/nested-pages


Otherwise, you could indeed have your content nested inside of a main parent wrapper.

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!