No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Redirect to Page 404

    Framework
    4
    5
    866
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jhon last edited by

      Hi.
      I need to redirect the user to page 404.vue after a query in ssr mode.

      preFetch ({ store, currentRoute, redirect }) {
          const p1 = store.dispatch('main/fetchCategoria', currentRoute.params.slugCategoria)
          p1.then((response) => {
            // Empleos por categoria
            const params = `categoria__slug=${currentRoute.params.slugCategoria}`
            return store.dispatch('main/fetchEmpleosCategoria', params)
          }).catch((e) => {
            if (e.response.status === 404) {
              redirect({ path: '404/' }) // this does not redirect
            }
            if (e.response.status === 500) {
              redirect({ name: 'error500' })
            }
          })
        },
      

      any suggestion?
      Thanks

      dobbel beets 2 Replies Last reply Reply Quote 0
      • dobbel
        dobbel @jhon last edited by

        @jhon said in Redirect to Page 404:

        if (e.response.status === 404) {
        redirect({ path: ‘404/’ }) // this does not redirect
        }

        could it be as simple as this:

         if (e.response.status === 404) {
                redirect({ path: '/404' }) //  /404 instead of 404/
              }
        
        1 Reply Last reply Reply Quote 0
        • beets
          beets @jhon last edited by

          @jhon As dobbel said you might have to change your path, but also with preFetch, if you want quasar to wait for any asynchronous call, you need to either return a promise or use async preFetch. Since you have two store dispatches, using async is probably easier:

            async preFetch ({ store, currentRoute, redirect }) {
              try {
                await store.dispatch('main/fetchCategoria', currentRoute.params.slugCategoria)
                // Empleos por categoria
                const params = `categoria__slug=${currentRoute.params.slugCategoria}`
                await store.dispatch('main/fetchEmpleosCategoria', params)
              } catch(e) {
                // console.log(e) here, as e.response.status may not longer be correct
                if (e.response.status === 404) {
                  redirect({ path: '404/' }) // this does not redirect
                }
                if (e.response.status === 500) {
                  redirect({ name: 'error500' })
                }
              }
            },
          
          
          J 1 Reply Last reply Reply Quote 0
          • J
            jhon @beets last edited by

            @beets Excelent…
            Muchas gracias…

            1 Reply Last reply Reply Quote 0
            • C
              Cobeland last edited by

              Very nice!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post