From c593e3fb7e10f313bedc93a2a9f930f753b07017 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Tue, 4 Jun 2024 16:57:21 +0300 Subject: [PATCH] Make external links open in the same tab Signed-off-by: Olga Bulat --- frontend/src/components/VLink.vue | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/VLink.vue b/frontend/src/components/VLink.vue index 0c811ea84d7..89b8b9b09b9 100644 --- a/frontend/src/components/VLink.vue +++ b/frontend/src/components/VLink.vue @@ -40,20 +40,17 @@ * Links with `href` starting with `/` are treated as internal links. * * Internal links use `NuxtLink` component with `to` attribute set to `localePath(href)` - * External links use `a` element. If `href` does not start with `#`, they are set to - * open in a new tab. + * External links use `a` element, and open in the same tab. */ import { computed, defineComponent } from "vue" import { useContext } from "@nuxtjs/composition-api" -import { useAnalytics } from "~/composables/use-analytics" - import { defineEvent } from "~/types/emits" import VIcon from "~/components/VIcon/VIcon.vue" type InternalLinkProps = { to: string } -type ExternalLinkProps = { target: string; rel: string } +type ExternalLinkProps = { rel: string } type DisabledLinkProps = { role: string } type LinkProps = | InternalLinkProps @@ -128,20 +125,20 @@ export default defineComponent({ return null } else { // External link should open in a new tab - return { target: "_blank", rel: "noopener noreferrer" } + return { rel: "noopener noreferrer" } } } // if href is undefined, return props that make the link disabled return { role: "link" } }) - const { sendCustomEvent } = useAnalytics() + const { $sendCustomEvent } = useContext() const handleExternalClick = () => { if (!checkHref(props) || !props.sendExternalLinkClickEvent) { return } - sendCustomEvent("EXTERNAL_LINK_CLICK", { + $sendCustomEvent("EXTERNAL_LINK_CLICK", { url: props.href, }) }