Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
How to show error page without changing current URL

I have a custom 500 error page called 500.tsx and I want to able to show this page when request from client fails with status of 500, but keeping client on old url (for example /auth/register). I have a axios listener on error which should do all the work. But could not find a way to do this using next/router. Any help appreciated

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Didn't realize OP wanted to show 500 page at first.

You could look into router.isFallback but I am not entirely sure if that's appropriate for this. It's supposed to be for Page Loading Indicators, but in your case, since the page will never load, it could work.

https://nextjs.org/docs/basic-features/data-fetching#fallback-true

 return router?.isFallback 
   ? <Custom500Page/>
   : <RegularPage/>

You can set this variable from getStaticPaths method, which runs during build time and is usually used for [slug] pages.

// This function gets called at build time
export async function getStaticPaths() {
  // Fetch paths to your slug pages here

  return {
    // paths,
    fallback: true
  }
}

Showing 404 page is quite straight forward & This is how we do.

Rendering 404 page

You can conditionally export a variable called notFound as true from getStaticProps method.

If the URL is invalid and you don't data to render the page, you simply pass that notFound prop as true and then the default or custom 404 page will show up automatically preserving your invalid url.

// This function gets called at build time
export async function getStaticProps({ params, preview = false }) {
  let pageData

  try {
    // fetch pageData from API here
  } catch (error) {
    // catch errors
  }

  // check validity or emptyness of data
  // invalid URL (slug) -> empty data from API
  // valid URL (slug) -> valid data from API

  return isObjectEmpty(pageData)
    ? { notFound: true }
    : {
        props: {
          pageData
          // pass other props to the page
        }
      }
}

NextJS Docs on getStaticProps & not-found

https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda