Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
next.js getInitialProps doesn't work at mobile browser

I have an app works perfectly (with no error) on desktop but when I use **mobile device ** ,I found that all pages can not trigger getInitialProps method at client side only if i navigate through Link component

This My code :

return(
  <>
   <Head>
      <title>
        welcome to Anas Behhari | blogging posts for
        {StaticFunction.Dateit(new Date())} |
        {new Date().getFullYear() - 1 + "-" + new Date().getFullYear()}
      </title>
  </Head>
   
  <div className="main">
      <div className="container">
        <div className="row">
          <div className="col-lg-10 offset-lg-1 js-post-list-wrap Blogs-con">
            <h2 className="h4 section-title">
              <span> Latest posts </span>
            </h2>
            {Blogs.map((blog) => (
              <Article blog={blog} key={blog._id} />
            ))}
            {BlogList}
          </div>
        </div>
      </div>
    </div>

  </>
)

blogs.getInitialProps = async (ctx) => {
 try {
  const res = await axios.get("http://localhost:3000/api/blogs?offset=0&max=5");
  const Blogs = res.data;
  return { Blogs };
  } catch (error) {
  return { error };
}

};

export default blogs;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Well, after 2 days of searching on the internet I figured out that I just need to change a bit inside the getInitialProps function.

The main factor was to get rid of the Axios and replace it with Fetch API

export async function getStaticProps() {
    const res = await fetch(`http://localhost:8080/api/blogs}`)
    const Blogs = await res.json()
    if(!Tags) return {props:{error:true}}
    return {
     props: {
       Blogs,
     },
    }
}

if this solution didn't work getServerSideProps instead of getStaticProps

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda