Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Vue router beforeRouteEnter - after refreshing the page, the button name disappears

<script>
export default {
  name: 'TEST',
   data() {
    return {
      prevRoute: ''
    }
  },
  methods: {
    goBack() {
      return this.$router.go(-1);
    },
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      vm.prevRoute = from.name
      console.log(from.name)
    })
  },
}
</script>
<template> 
 <div>
  <button @click="goBack" class="back">{{ prevRoute }}</button>
 </div>
</template>

Vue router beforeRouteEnter - after refreshing the page, the button text {{ prevRoute }} disappears. What other ways are there to display text in the button of the previous page?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That's not possible at all, your from route will be always empty on refresh. The best approach I can figure out is by storing your route from.name in your localStorage and set that item only if from.name exists

beforeRouteEnter(to, from, next) {
    if (from.name) localStorage.setItem('from_route', from.name)
    next()
},
        

Then in your mounted hook set the prevRoute value as per localStorage item

mounted () {
    this.from_route = localStorage.getItem('from_route')
},

Of course, you will face the same issue if someone shares you a link and you are not coming from any other page.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!