This is just a short note about how to redirect after catching error in fetch hook in server side rendering- Nuxt js application.
async fetch() {
    try{
        // whatever you need 
        const route = this.$router.history.current.path;
        this.routeName = route   
       const finalTitle = route.replace(/\\|\//g, "");
       const res = await 
       this.$axios.$get(`productBySlug/${finalTitle}/`);
       this.obj = res.data;
   }
   catch({response}){
       // others code goes here 
       this.$nuxt.context.redirect({path:'/'})
   }
},
 

 
    
Top comments (0)