0

i want the specific url so that the user can copy it and access through that link. But everytime i am trying to do so in the same browser the link is opening. But in the other browser it is changing the url and redirecting it to home page

template of vue.js app

<vs-alert color="primary" title="Share this link " active="true">
         <vs-progress indeterminate color="primary"></vs-progress>
         <a :href="path">
         <span class="cursor-pointer" >  Copy Link  </span></a>
         {{ fullUrl }}
</vs-alert>

this is the script

computed:{
        path(){
           var paths = this.$router.resolve({name: 'recruiter-postedjob', params: {id: this.id}}).href 
           this.fullUrl = window.location + paths
           return paths
        },

when in another browser i am trying to use the same link it is changing the link as

http://localhost:8080/dashboard/JobDetails/5uZzQ2xlRuk1NyScuhqL/recruiter/postedjob/5uZzQ2xlRuk1NyScuhqL

If anyone could tell me a way to generate a link.

Michal Levý
  • 33,064
  • 4
  • 68
  • 86
mayank3503
  • 315
  • 4
  • 17

1 Answers1

0
  1. If you don't want browser to open the link, why use <a> in the first place ? You will need some kind of textbox anyway, because browsers do not allow JavaScript to put something into clipboard (there is no clipboard.push API). If you really want to use <a>, you must prevent default browser on click behavior (navigating to href)
<a :href="path" @click.prevent.stop="onClick(path)"> Copy link </a>
  1. You are merging your current page's full URL with the relative url of the route. Use window.location.origin instead of window.location in your computed property

  2. You will need to implement onClick handler to Copy output of a JavaScript variable to the clipboard

Working example

Michal Levý
  • 33,064
  • 4
  • 68
  • 86
  • in your example when i copy the url and try opening it in incognito tab it is redirecting to the actual page. But in this i am getting the url .. but when i try and open the recruiter-jobposted page.. it is redirecting me to the home page and changing the url as **http://localhost:8080/home?to=%2Fpostedjob%2F1jPJOPDj76D7ODhzOEcq** – mayank3503 Dec 11 '19 at 19:43
  • Check the url copied into the clipboard. If it seems ok (as other urls to your `recruiter-postedjob` route) and after pasting it into browser's url bar __the server__ is redirecting you somewhere else, than its your server's problem.... – Michal Levý Dec 11 '19 at 19:53