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

210
Views
Keep params while navigating through routes

How can I keep params while navigating through routes. The parameter/parameters have to be in every page of the application (not only in nested routes). In angular I can do this with this._router.navigate([''], { queryParamsHandling: 'merge' }), but how can I do it with vue.js?

Example of base routes:

// base route 1 -> http://example.test/?user_code=1234&member=false
// base route 2 -> http://example.test/?user_code=56789&member=false
// base route 3 -> http://example.test/?user_code=4321

How can I keep the parameters user_code and member in every route I navigate?

Example of what I want

// navigated route 1 -> http://example.test/about?user_code=1234&member=false
// navigated route 2 -> http://example.test/whatever_page?user_code=56789&member=false
// ...

Why I need this? Because then I will need the params to do things in the app Ex: this.$route.query.user_code == '1234' ? 'do this' : 'do that';

Thank you in advance!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A typical approach would be to use state and push the fullPath of the route into that state attribute (likely an Array).

With vuex:

// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    paths: []
  },
  mutations: {
    PUSH_PATH (fullPath) {
      paths.push(fullPath)
    }
  },
  actions: {
    pushPath(commit, fullPath) {
       commit("PUSH_PATH", fullPath)  
    }
  } 
})
// in a component
import { mapActions } from "vuex";
...

  methods: {
    ...mapActions("pushPath")
  },
  created() {
    this.pushPath(this.$route.fullPath)
  }

Now if you used pushPath, when your view is created, it would add the fullPath to an array that you could later make decisions about either through injection, inspection, etc.

Another popular option, especially when making decisions based on routes is to use "Navigation Guards". These are functions that intercept the route and allow you to perform some action. More details are available here: https://router.vuejs.org/guide/advanced/navigation-guards.html

over 4 years ago · Santiago Trujillo 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!