question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically creating <NuxtLink> with <Component> no longer works

See original GitHub issue

Environment

  • Operating System: Darwin
  • Node Version: v14.17.6
  • Nuxt Version: 3.0.0-27454426.4cefce4
  • Package Manager: npm@8.5.4
  • Bundler: Vite
  • User Config: meta, publicRuntimeConfig
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-92nabt?file=app.vue

Describe the bug

Code like this used to work, but no longer does:

<Component :is="1 === 1 ? 'NuxtLink' : 'a'" to="/example">
  This should be a link to the "Example" page
</Component>

Additional context

Two others with the same problem:

https://discord.com/channels/473401852243869706/897487139888062506/953235583403196476

https://discord.com/channels/473401852243869706/897487139888062506/953281246472056882

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
danielroecommented, Apr 7, 2022

The new way to pull in a component that is not globally registered is to use resolveComponent.

See docs and this comment.

Example with NuxtLink.

3reactions
jerryjappinencommented, Mar 21, 2022

Also ran into this. I very often have components that might or might not render a link, just like @przyb mentioned there. I might have a button component that does something like this:

  computed: {
    is () {
      if (this.to) {
        return 'NuxtLink'
      } else if (this.href || this.mailto || this.tel) {
        return 'a'
      }

      return 'button'
    }
  }

Mostly I do this so that I don’t have to duplicate or spread other relevant button logic/styling between multiple components.

Another reason I might do something like this, is that part of the data might still be loading. I might know that I want to render a list of objects, but e.g. a component of the URL necessary to render the link is not available yet. Maybe client is still waiting for the rest of the data to load, or the data is only available after hydration but not server-side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a dynamic nuxt-link with data fetched from a ...
Clicking on the login button correctly takes the app to the accountHandle page. However why is the URL incorrect? The Url after clicking...
Read more >
Built-in Components - Nuxt
The linkActiveClass works the same as the vue-router class for active links. If we want to show which links are active all you...
Read more >
How We Helped Bring You the New Nuxt 3 Link Component
With the new <NuxtLink> , we can now link to anything. We no longer have to choose between an anchor <a> tag or...
Read more >
Dynamic Routing in Nuxt - DEV Community ‍ ‍
Dynamic routing allows rendering your Vue components conditionally. ... Dynamic pages can be created when you don't know the name of the ...
Read more >
Creating a Strapi Dynamic Zone & Rendering it in your Nuxt.js ...
In this tutorial, you will build a company website with Nuxt.js that ... for your component; Add a Text field (long text) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found