Template:
<button @click="redirect">Search</button>
<input v-model="searchQuery" v-on:keyup.enter="redirect" type="text">
Js script:
export default {
methods: {
redirect: function() {
if (this.searchQuery) {
this.$router.push({
name: 'tag',
params: {
tag: this.searchQuery
}
})
}
}
},
data() {
return {
searchQuery: ''
}
}
}
Here's the problem. If I click enter in the input, the redirection will work fine to the route with name tag
. If I click the button, the redirection will try to happen (I will see in browser url the change) but then instantly it will go back to the existing page