SelfishCosmonaut
SelfishCosmonaut

Reputation: 99

Using Axios to resolve VueJS Route

Routes in main.js

{
    name: 'match',
    path: '/match/:id',
    component: Match,
    props: true
},

And in the main component (separate file) that fires the GET request:

axios({
      method: "GET",
      url: "/match/" + id,
      crossdomain: true,

)}

Chrome tells me it's a 404. But when I open the provided link, it resolves and works?

enter image description here

Upvotes: 0

Views: 974

Answers (2)

elad frizi
elad frizi

Reputation: 725

You should try

this.$router.push("/match/" + id)

While 'this' is a Vue instance. You need to use vue-router API to navigate inside your application, not axois.

Upvotes: 1

SelfishCosmonaut
SelfishCosmonaut

Reputation: 99

Solved by changing component Axios call to

url: this.$router.push({ name: 'match', params: { id: id }})

As per https://router.vuejs.org/guide/essentials/named-routes.html

Upvotes: 0

Related Questions