Tuesday 5 January 2021

VueJs get referral URL that called a specific route

I'm trying to get the referral URL from where a specific route from my VueJS app was called.

The flow is:

  1. Route1 redirects to (outside) URL1 with a returnURL
  2. (outside) URL1 performs some actions and returns to returnURL
  3. ReturnUrl matches Route2 and shows a view (only if it comes from URL1)

I've tried with:

router.beforeEach((to, from, next) => {
  console.log(to)
  console.log(from)
  next()
})

But the from url is always /. Also I tried with:

this.$route.query

(from How to get http refere in vuejs?)

And with plain JS with something like:

var referrer = document.referrer;

Finally I tried with this plugin: https://www.npmjs.com/package/@tozd/vue-router-referer without success.

The problem is that I don't have any clue if the user called directly the returnUrl (forbidden) or it's a call from the outside service URL1 (valid).

It's this possible?

I checked: Can I get the referrer?



from VueJs get referral URL that called a specific route

No comments:

Post a Comment