I am having an issue because I have a component that is used as a child component in two places, and I want to create a back button that sends the user back to the correct route. I can do it with the individual parents:
<button open ref="backBtn" :back="`/parent1/${this.$route.params.id}/home`" />
<button open ref="backBtn" :back="`/parent2/${this.$route.params.id}/home`" />
But what I really want is a single button with a method that says:
Okay, you came from parent 1? Then use :back="/parent1/${this.$route.params.id}/home
"
else, use :back="/parent2/${this.$route.params.id}/home
"
Can it be done?
You can just do
this.$router.back()
or$router.back()
, it will go back from where it comes from.If it doesn't work for you, you can use in your child the
this.$parent
to get information from your parent, even if it is not recommended.