Home > OS >  Can't access my pages by URL, only by links in next js
Can't access my pages by URL, only by links in next js

Time:01-04

I have an application built with next JS. It works fine in development, but when published to the internet, I have a problem. The only way I can access the pages in the application are by the links on the home page, that link to those pages. For example, I get a 404 error if I type in www.example.com/about, but if I click the link that routes to it, everything is fine.

CodePudding user response:

I couldn't comment because of my experience point. Could you share your code for higher components/pages? For now what I understand is your browser can't fetch the data before render, so you get an error. It' is a wild guess but maybe you can add a condition to your components(for example for url/about let's say you render about() component) that

if (!data){ return <div>Loading</div>}  

This is an approach that I used at React apps(never used next) but since they are quite similar it might help you.

CodePudding user response:

I guess its same to this question:https://stackoverflow.com/questions/54815348/nextjs-page-goes-to-404-on-refresh

  •  Tags:  
  • Related