diff --git a/packages/@vuepress/theme-default/components/SidebarLink.vue b/packages/@vuepress/theme-default/components/SidebarLink.vue index 7d128b4a98..243ce7630b 100644 --- a/packages/@vuepress/theme-default/components/SidebarLink.vue +++ b/packages/@vuepress/theme-default/components/SidebarLink.vue @@ -28,7 +28,9 @@ export default { const active = item.type === 'auto' ? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug)) : selfActive - const link = renderLink(h, item.path, item.title || item.path, active) + const link = item.type === 'external' + ? renderExternal(h, item.path, item.title || item.path) + : renderLink(h, item.path, item.title || item.path, active) const configDepth = $page.frontmatter.sidebarDepth || sidebarDepth @@ -75,6 +77,19 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) { ]) })) } + +function renderExternal (h, to, text) { + return h('a', { + attrs: { + href: to, + target: '_blank', + rel: 'noopener noreferrer' + }, + class: { + 'sidebar-link': true + } + }, [text, h('OutboundLink')]) +}