Answer the question
In order to leave comments, you need to log in
How to redirect to a 404 page in vue if the server returned a 404?
Hello!
How to redirect user to 404 error page.
I have routes like this
{
path:"/catalog/:catalog",
name: 'products',
component: () => import('./views/products.vue')
},
{
path:"/:pathMatch(.*)*",
name: '404',
component: () => import('./views/pagenotfound.vue')
}
ajaxProductsbyCategoryFromDB(context,category){
axios.get("/api/products/"+category).then(responce =>{
context.commit('setProducts',responce.data.products)
})
// .catch(Что-то тут надо сделать?)
}
Answer the question
In order to leave comments, you need to log in
ajaxProductsbyCategoryFromDB(context,category){
axios.get("/api/products/"+category).then(responce =>{
context.commit('setProducts',responce.data.products)
})
.catch((error) => {
// Проверка на код ошибки
if (error.response.status === 404) {
// Перенаправление на именованный роут
router.push({ name: '404' })
}
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question