vue-router : how to remove underline from router-link
Asked Answered
P

10

42

This results in an underlined link:

<li><router-link to="/hello">Hello</router-link></li>

My understanding is that the router-link element generates an a tag.

I've tried these things in the CSS:

router-link{
    text-decoration: none;
}

router-link a{
    text-decoration: none;
}

router-link a{
    text-decoration: none !important;
}

..but unfortunately none of these work.

Popularize answered 28/6, 2017 at 16:52 Comment(0)
H
15

Vue component tags don't generate HTML tags.
Look in the DOM inspector to see what HTML tags actually exist.

You need to use regular classnames.

Helaine answered 28/6, 2017 at 16:54 Comment(1)
Ah, I see what you're talking about. The router-link turns into an a. li a { } in CSS seems to work. Thanks.Popularize
V
50

If anyone using Vuetify comes across this question, note that the styling below do not work due to Vuetify's in built styles. You must instead use inline CSS styling:

<router-link
 style="text-decoration: none; color: inherit;"
 to="/hello">
Vixen answered 22/4, 2020 at 3:6 Comment(0)
L
29

It is Converted into <a ...
So to remove the underline try this

a { text-decoration: none; }
Londoner answered 4/6, 2019 at 11:35 Comment(1)
This one worked for me. Thank you. I added a script to the vue.Louannlouanna
U
23

You can try targeting the list item link like this:

li a {
    text-decoration: none;
}
Unbelievable answered 28/6, 2017 at 16:59 Comment(0)
H
15

Vue component tags don't generate HTML tags.
Look in the DOM inspector to see what HTML tags actually exist.

You need to use regular classnames.

Helaine answered 28/6, 2017 at 16:54 Comment(1)
Ah, I see what you're talking about. The router-link turns into an a. li a { } in CSS seems to work. Thanks.Popularize
F
14

You can use the tag prop of router link to use the li css class like this:

<li><router-link tag="li" to="/hello">Hello</router-link></li>

The link will now use li css propertys but still work as like a normal router link.

Feminize answered 19/11, 2019 at 12:29 Comment(0)
W
9

Add a class to router-link tag:

<router-link class="routerLink" to="/hello">Hello</router-link>

Then give css to the class:

.routerLink{
     text-decoration: none;
 }

This should work :)

Wedlock answered 5/3, 2020 at 17:18 Comment(0)
C
2

SCSS

div /deep/ .v-list a {
    text-decoration: none;
}

CSS

div >>> .v-list a{
    text-decoration: none;
}
Chops answered 6/5, 2020 at 6:48 Comment(1)
/deep/ is deprecated [Deprecation] /deep/ combinator is no longer supported in CSS dynamic profile.Exceptionable
S
2

Even in React-Router. The Link tag makes the text underlined. Because any text (h1, h3, p) inside tag are converted to anchor tags so:

a{text-decoration: none;}
Surgical answered 29/3, 2022 at 19:12 Comment(0)
P
0

Although this answer seems quite obvious. I think my colleagues above forgot to mention that if you are using vuetify with the Laravel framework this problem can be solved as follows. Access:

resources\sass\app.scss file

And comment out the line:

@import '~bootstrap/scss/bootstrap';

This usually resolves this type of problem, which is actually a library conflict.

Pasco answered 29/12, 2020 at 23:20 Comment(0)
D
0

If you are using Boostrap 5 you can use the class text-decoration-none

<router-link href="yourlink" class="text-decoration-none" >

</router-link>

see bootsrap documentation for reference. Just an additional information I am using Vue3 in my application

Denice answered 2/2, 2022 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.