0

I'm trying to pass a querystring value when I open a view. I have set up my router like this:

import Home from "../views/Home.vue";
import Summary from "../views/Summary.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: Home
  },
  {
    path: "/summary/:id",
    name: "Summary",
    component: Summary
  }
];

The home.vue has this link:

<a href="#" class="card-link" @click.prevent="goSummary(item.id)">View Item Summary</a> <!--item.id came from the v-for loop-->

The home.vue has this on the export default script

methods: {
  goSummary(id) {
    //do other things here
    this.$router.replace('Summary/'+id); //I'm supposed to see the view
  }
}

1 Answer 1

2

you can use :

<router-link :to="{ name: 'Summary', params: { id: item.id } }">
  View
</router-link>

or via javascript:

  this.$router.push({ name: 'Summary', params: { id: this.item.id } })

For further information, see vue router documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.