I have a vue
component that contains a method, the method contains this router push that tries to push to another vue
component:
GetAnimal.vue:
...
this.$router.push({
name: /viewanimal,
});
...
I have this mappings for the router:
router.js:
{
path: /viewanimal,
component: () => import('./views/DisplayAnimal.vue')
},
{
path: /getanimal,
component: () => import('./views/GetAnimal.vue')
}
However when the code inside the GetAnimal.vue
gets executed I get this in console:
And I get directed to http://localhost:8080/
.
I also tried
...
this.$router.push({
name: viewanimal,
});
...
but it doesn't work either.
EDIT:
I've tried:
router.js:
{
path: /viewanimal,
name: viewanimal,
component: () => import('./views/DisplayAnimal.vue')
},
{
path: /getanimal,
name: getanimal,
component: () => import('./views/GetAnimal.vue')
}
GetAnimal.vue:
console.log(this.animal: + JSON.stringify(this.animal)); //displays good JSON
this.$router.push({
name: viewanimal,
params: this.animal
});
DisplayAnimal.vue:
created() {
console.log(animal param: +
JSON.stringify(this.$route.params.animal)); //prints undefined
}
---The animal parameter doesn't seem to have been passed. I'm not sure if it's the problem with the router's path/name thing or something else---.
UPDATE:
Managed to make it work. This should be in GetAnimal.vue
:
this.$router.push({
name: viewanimal,
params: {
animal: this.animal
}
});