Skip to content

Commit 377da36

Browse files
committed
feat($theme-default): support nav config for attr of internal links
1 parent e8f91f8 commit 377da36

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/@vuepress/theme-default/components/NavLink.vue

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class="nav-link"
44
:to="link"
55
@focusout.native="focusoutAction"
6-
v-if="!isExternal(link)"
6+
v-if="isInternal"
77
:exact="exact"
88
>{{ item.text }}</router-link>
99
<a
@@ -42,22 +42,25 @@ export default {
4242
},
4343
4444
target () {
45-
return isMailto(this.link) || isTel(this.link) ? null : this.item.target || '_blank'
45+
return isMailto(this.link) || isTel(this.link) ? null : this.item.target
46+
|| (isExternal(this.link) ? '_blank' : '')
4647
},
4748
4849
isTargetBlank () {
4950
return this.target === '_blank'
5051
},
5152
5253
rel () {
53-
return isMailto(this.link) || isTel(this.link) ? null : this.item.rel || 'noopener noreferrer'
54+
return isMailto(this.link) || isTel(this.link) ? null : this.item.rel
55+
|| (this.isTargetBlank ? 'noopener noreferrer' : '')
56+
},
57+
58+
isInternal () {
59+
return !isExternal(this.link) && !this.isTargetBlank
5460
}
5561
},
5662
5763
methods: {
58-
isExternal,
59-
isMailto,
60-
isTel,
6164
focusoutAction () {
6265
this.$emit('focusout')
6366
}

packages/docs/docs/theme/default-theme-config.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module.exports = {
6262
themeConfig: {
6363
nav: [
6464
{ text: 'External', link: 'https://google.com', target:'_self', rel:'' },
65+
{ text: 'Guide', link: '/guide/', target:'_blank' }
6566
]
6667
}
6768
}

0 commit comments

Comments
 (0)