set target= '_blank' in router-link of vuejs 2.5
Asked Answered
J

5

12

Using vuejs 2.5 if there is a way in router-link to set

target= '_blank'

? I tried this way:

<router-link :to="{name: 'UserProfileView', params: {id: participantUser.user_id}, target: '_blank' }"  >  

but failed...

Thanks!

Jebel answered 15/1, 2018 at 15:37 Comment(1)
Possible duplicate of Can vue-router open a link in new tab?Grecize
C
33

You will add target='_blank' like on <a> tag

Hope is clear

Concinnate answered 15/1, 2018 at 16:34 Comment(5)
so it will be something like: <router-link :to="{name: 'UserProfileView', params: {id: participantUser.user_id}}" target= '_blank' >Concinnate
it won't work if tag is not a (for example tag="button")Cortege
@Cortege i think because by default router-link is an anchor tag with the target property, the button html element don't have itConcinnate
@Concinnate you mean in the router-link tag ?Affrica
@SalmaELHAJRAOUI, like the example on the first comment <router-link target= '_blank' >my link </router-link>Concinnate
B
1

You must to use method. Method looks something like this:

methods: {
     redirectToUserView(user) {
      const route = this.$router.resolve({
        name: 'UserProfileView',
        params: {id: participantUser.user_id},   
      });
      window.open(route.href, '_blank');
    },
 }
Birl answered 19/8, 2021 at 14:57 Comment(0)
I
0

Below code is to open a new tab with parameter.

With router link=

<router-link
                  :to="{ name: 'task_section',query: {reportId: item.task,}}"
                  target="_blank"> Link Text
              </router-link>

Now access to the sented data

this.$route.query.reportId
Idea answered 20/12, 2021 at 7:48 Comment(0)
K
0

Perfectly worked for my code "target='_blank'" with external redirect.

<b-dropdown-item
                :key="props.row.banner_id"
                :to="{name:'banners-preview',
                      params: { id: props.row.banner_id } }"
                target='_blank'
              >
                <feather-icon
                  icon="ExternalLinkIcon"
                  class="mr-50"
                />
                <span>Preview Link</span>
</b-dropdown-item>
Kiesha answered 3/10, 2022 at 8:36 Comment(0)
T
0

try this :

<template>
  <div id="app">
      <button @click="gotoContact()">Contact</button>
  </div>
</template>

<script>
export default {
  name: "app",
  methods: {
    gotoContact() {
      let route = this.$router.resolve({ path: "/contact" });
      window.open(route.href);
    },
  },
};
</script>
Tithe answered 21/11, 2023 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.