DEV Community

sium_hossain
sium_hossain

Posted on

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

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

Top comments (0)