title: Get previous site url in a Single Page Application using javascript
body: <p>I'm working on a vue single page application.</p>
  
  <p><strong>Situation</strong>: I have a page which displays <code>1..*</code> results (Page A), if there is only 1 result available, then this result is automatically selected; meaning the user is redirected to the items detail page (Page B). </p>
  
  <pre><code>[Page A] &lt;-&gt; [Page B]
  </code></pre>
  
  <p><strong>Problem</strong>: if the user is on Page B and navigates back then the 'auto-select'-clause is triggered again which results in a redirect again to Page B. This means you cannot navigate back once you've entered Page B - this is unacceptable. </p>
  
  <p><strong>Thoughts</strong>: The best solution I can think of is to add a check to the auto-select clause which matches the origin (where the user came from, e.g. Page B) to the desired destination (where to user is redirected to, e.g. also Page B), and if they do match, do not trigger the redirect. The problem is that I have no way of knowing where the user was before.</p>
  
  <p>I tried to use <code>document.referrer</code> but this isn't suitable for a single page application.</p>
  
  <p>I tried to work with vue-router properties, but none of which brought me any futher.</p>
  
  <p>The only other solution I can think of is to store each navigation in a cookie (or similar) to match against, but since this is quite a rare case I try to avoid having too much of an overhead. </p>
  
  <p>Any idea? Is there something similar like <code>document.referrer</code> but for single page applications? Or is there a way to extract information from the <code>history</code>?</p>