Reputation: 1985
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!
Upvotes: 15
Views: 14517
Reputation: 2240
You can't access your routes directly. you have to do this little hack for that.
npm run build
command you have to go to the build folder of your react application folder.read more about this issue: here
Upvotes: 14
Reputation: 413
Follow below step to resolve(only 4 surge):
npm run build
cd build
cp index.html 200.html
surge
From here you can continue as usual
Upvotes: 33
Reputation: 6117
Change your build step in package.json
"build": "react-scripts build && cp build/index.html build/200.html"
Source: https://medium.com/superhighfives/serving-client-side-routing-with-surge-sh-7b705542cf3
Upvotes: 7