2π
β
I suspect that you have a <form>
tag wrapping the button and input. And the button
click trigger form submission so the page reload and returns to the same page.
Try modifying the click event into @click.prevent="redirect"
.
.prevent
will have the effect of event.preventDefault()
on the click event.
Will delete this answer if using <form>
is not the reason.
π€Jacob Goh
0π
I donβt know what is causing the error. Maybe check if this.searchQuery
has a value when you try to redirect with the click event. In either case, I think you are better of using <router-link />
to redirect your page. If you want the router-link to look like a button then pass tag='button'
as in this example:
<router-link tag='button' :to="{ name: 'tag', params: { tag: this.searchQuery }}"> search </router-link>
π€samayo
Source:stackexchange.com