2👍
✅
Assuming your ajax response returns an error code, then you should be able to catch this and handle it in your response, I’m using axios here:
axios.get('/api/results/' + this.$route.params.id).then(response => {
// success, set the model variables
}).catch(error => {
// Nope, let's check what the error was
if(error.response.status === 404){
// redirect user
this.$router.push('/notFound')
}
})
If you don’t get an error response you can just redirect when data is null:
axios.get('/api/results/' + this.$route.params.id).then(response => {
// success, set the model variables
if(response.data == null){
this.$router.push('/notFound')
}
// success, set the model variables
}).catch(error => {
// Handle errors
})
Source:stackexchange.com