Nuxt.js: Nuxt-link and router-link don't create href attribute

Created on 14 Oct 2020  路  8Comments  路  Source: nuxt/nuxt.js

Most helpful comment

No, i expect the behavior of :href="undefined" and no href prop at all to be equal. So you can use this component

  <component
    :is="tag"
    :href="href"
    :target="target"
    :to="to">
  </component>

either with props {tag: 'a', href: 'google.com', target: '_blank'} and with {tag: 'n-link', to: '/home'} and get href attribute already existing in page source code in both cases

All 8 comments

You should not need to set the href as NuxtLink will transform to an a tag on the server side automatically.
Example

grafik
https://github.com/manniL/lichter.io/blob/main/components/Navbar.vue#L36-L40

I know how to handle it to make it work, but i think this behavior is inconsistent. When you create dynamic component like this

  <component
    :is="tag"
    :href="href"
    :target="target"
    :to="to">
  </component>

that can be either <a> or <n-link>, so there should be all props. Once again, i know how to make it work using v-bind or separate template, i created an issue because i think this is a bug.

Okay, so to clarify that:
The behavior you are expecting is that NuxtLink should use a set href prop (if provided)?

No, i expect the behavior of :href="undefined" and no href prop at all to be equal. So you can use this component

  <component
    :is="tag"
    :href="href"
    :target="target"
    :to="to">
  </component>

either with props {tag: 'a', href: 'google.com', target: '_blank'} and with {tag: 'n-link', to: '/home'} and get href attribute already existing in page source code in both cases

Got it!

As you mentioned, the same issue appears with RouterLink too, right?

Yes, the same behavior.

Then https://github.com/vuejs/vue-router might be a better place for this issue. <NuxtLink> inherits <RouterLink> behavior 鈽猴笍

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  路  3Comments

gary149 picture gary149  路  3Comments

maicong picture maicong  路  3Comments

danieloprado picture danieloprado  路  3Comments

uptownhr picture uptownhr  路  3Comments