When I wrote the following code:
axios.post('/user', { email: this.email })
.then(
(response) => {
if (!response.data) {
this.$router.push({ path: '/register', params: { user: defaultUser } });
} else {
this.$router.push({ path: '/login', params: { user: response.data } });
}
},
(error) => {
console.log(error);
}
);
The compiler shows error @typescript-eslint/no-floating-promises: Promises must be handled appropriately or explicitly marked as ignored with the void operator.
I also tried put a catch block after then block but it's still the same problem.
axios.post('/user', { email: this.email })
.then((response) => {
if (!response.data) {
this.$router.push({ path: '/register', params: { user: defaultUser } });
} else {
this.$router.push({ path: '/login', params: { user: response.data } });
}
})
.catch((error) => {
console.log(error);
});
I also figured out that the problem disappears when I comment out this.$router.push
. So the problem might deal with redirecting route and resolving promise. Maybe it's better to rephrase the problem to 'how to redirect route without leaving unresolved promise'? I hope I make the question clear.