Skip to content

Commit

Permalink
fix: add option to open local links in a new tab (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusznarowski authored and mercs600 committed Oct 17, 2023
1 parent 30b4cdf commit f7640e8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/components/T3HtmlParser/T3HtmlParser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export default {
// If target is still not a link, ignore
if (!(target instanceof HTMLAnchorElement)) { return }
const href = target.getAttribute('href')
// Get link target, if local link, navigate with router link
if (href && href[0] === '/') {
const hrefTarget = target.getAttribute('target')
const isCtrlKeyPressed = event.ctrlKey || event.metaKey
const openInNewTab = (hrefTarget && hrefTarget === '_blank') || isCtrlKeyPressed
// If link is local, not set to open in a new tab,
// and Ctrl (or Cmd) key is not pressed, navigate with router link
if (href && href[0] === '/' && !openInNewTab) {
event.preventDefault()
this.$router.push(href)
}
Expand Down

0 comments on commit f7640e8

Please sign in to comment.