#Short_note- Redirect and catch errors in fetch hook Nuxt (SSR)

sium_hossain - Jun 19 '22 - - Dev Community

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:'/'})


   }

},
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player