Skip to content

Commit

Permalink
feat(nav-link): handle external links too
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Jul 3, 2022
1 parent d8e80d3 commit 51196b9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/nav-link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,20 @@ const clazz = computed(() => {
}
})
const hasExternalLink = computed(() => {
const { href } = props
const { hostname } = window.location
return href.startsWith('http') && !href.includes(hostname)
})
const hasAnchor = computed(() => {
const { href } = props
return !hasExternalLink.value && href.includes('#')
})
function click(event) {
if (props.href.includes('#') && !props.href.includes('/')) {
// let the browser do the scrolling
if (hasExternalLink.value || hasAnchor.value) {
// let the browser do the work
} else {
event.preventDefault()
event.stopImmediatePropagation()
Expand Down

0 comments on commit 51196b9

Please sign in to comment.