vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

document.referrer is empty when navigating via links to another view. #3892

Closed dev-samples closed 3 months ago

dev-samples commented 3 months ago

Version

3.5.1

Reproduction link

github.com

Steps to reproduce

Navigate from this view:

<template>
  <div>
    <div class="about">
      <h1>This is an about page</h1>
    </div>
    <nav>
      <router-link to="/another">Another</router-link>
    </nav>
    <router-view />
  </div>
</template>

to this view:

<template>
  <div class="another">
    <h1>This is another page</h1>
    <!--     <p>Coming from (referrer): {{ myvar }}</p> -->
  </div>
</template>

<script>
export default {
  name: "AnotherView",
  data() {
    return {
      myvar: "",
    };
  },
  mounted() {
    console.log("document.referrer", document.referrer);
    this.myvar = document.referrer;

    // Accessing the document content and referrer
    this.documentContent = document.documentElement.outerHTML;
    this.documentReferrer = document.referrer;

    console.log(" - - Document Referrer:", this.documentReferrer);
  },
};
</script>

What is expected?

That it prints the value/path of the previous (/about) route in the target route (/another)

What is actually happening?

It just print empty


Upgrading to a later version of vuejs is not an option at the moment. Did read: https://github.com/vuejs/vue-router/issues/883

but not sure if it what I am hitting here.

posva commented 3 months ago

This is expected behavior in SPAs using history.pushState(). I recommend you using the Discord server if you need help with what you are trying to do regarding the document.referrer property