Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surge-deployed React app - getting 404 Page Not Found

I have an app that is running on (http://simple-pen.surge.sh). This is built with React/Redux for Front-end and Rails for back-end. When I get on the site, I can either sign-up or sign-in and issue a JWT token for the user. Once logged in, I have a set of notebooks I can view. However, it's only when clicking on a notebook, I get redirected to a 404 Page Not Found error.

I'm not sure why I get an error when making the GET request to certain pages. Trying to access "http://simple-pen.surge.sh/notebooks/1/notes" url, but fails. In one scenario, I have it set so if the user is logged in, the "simple-pen.surge.sh" root path redirects the user to their notebooks route i.e. "http://simple-pen.surge.sh/notebooks" which renders the page, but when I make an actual request for this URL directly, I then get the error.

Below are links to GitHub repos for React and Rails app respectively. https://github.com/jamesvphan/simplepen-react https://github.com/jamesvphan/simplepen

Any help or knowledge as to why this is occurring would be great!

like image 506
jamesvphan Avatar asked May 08 '17 19:05

jamesvphan


People also ask

How do I show 404 pages in react JS?

Creating a 404 Page In React, you do this by creating a not found component that will render on routes that don't exist. This article assumes you already have a working React application with routing set up. If you don't, create a React application and then install React Router. Create a new file called NotFound.


2 Answers

You can't access your routes directly. you have to do this little hack for that.

  1. After you run the npm run build command you have to go to the build folder of your react application folder.
  2. Take a copy of index.html file. then past it in the same place and rename it as 200.html now it will work as we wish. This is all for today.

read more about this issue: here

like image 94
isuruAb Avatar answered Oct 31 '22 05:10

isuruAb


Follow below step to resolve(only 4 surge):

  1. npm run build
  2. cd build
  3. cp index.html 200.html
  4. surge

From here you can continue as usual

like image 30
Shubham Prakash Avatar answered Oct 31 '22 06:10

Shubham Prakash