Netlify page not found 404 after clicking a button - reactjs

I'm new to here, just have a question and want to solve it. I have deployed my app on netlify, everything works fine at localhost, but when I tested it on netlify with a function. It threw an error like this.
The page not found but when I tried reloading with that same URL, It still accessed. I use heroku for deploying api and netlify for client.
So what is the problem here? Can anyone help me, thanks!
My app for anyone would like to test: http://myblogapp123.netlify.app

create a file inside the public folder. Name it "_redirects"
inside _redirects file, paste this: /* /index.html 200
Then build your project and deploy it again. Hopefully, It'll work.

Related

Sanity Slug works in localhost but not on Netlify

So I am building a react and sanity blog website. When I run the app on localhost, my blog post slugs work, copying the slugs and opening in a new tab works but when I deployed it on Netlify, I get a 404 page, what going on?
Thank you for your time
Try this, it worked for me
In your public folder, create a "_redirects" - without the quotes, file and add the following lines of code
/* /index.html 200
Hope it works for you.

Reactjs site doesn't load any sub pages other than homepage, hosted on Netlify

I hosted one of my website on Netlify. Site was built with ReactJS.
After deploying on Netlify, I can view the homepage but can't load any of the other pages.
Site works totally fine in localhost.
Is this a problem with routing?
I used react-router for routing.
Try to create a new file in your project public folder called _redirects then add this inside it
/* /index.html 200
its been solved here before Netlify does not recognize the URL params when using react-router-dom
Just found this blog post. This gives a good explanation.
Creating a file called _redirects in the public folder and adding this code
/* /index.html 200
solves the problem.
https://dev.to/rajeshroyal/page-not-found-error-on-netlify-reactjs-react-router-solved-43oa

Netlify doesn't display all website pages

I am using Netlify to deploy a website. It was built with ReactJS and locally everything works. After deploying it on Netlify only the landing page works.
The website is a simple static website for hosting my portfolio.
The main website is www.myname.com while projects are located on www.myname.com/project-name-case-study
Anything under www.myname.com/project-name-case-study leads to a "Page Not Found" screen. I'm just not sure where to even start here. I'm new to website deployment
Just figured it out. The issue was specifically related to React-Router. This freeCodeCamp article shows how to easily fix it.
As this article mentioned:
"Create a new file with the name _redirects inside the public folder of our project and add the following contents inside it:"
/* /index.html 200

If I refresh the browser my react app are being page not supported error message

I'm new in react app development, I just build my practice app and deployed it through Netlify. I can visit my app and everything is fine till I refresh my window. Refreshing the window comes with an error page not found. what should I do to solve this problem?
You may need to look at providing a _redirects file in your root directory. See https://docs.netlify.com/routing/redirects/
For example,
/* /index.html 200
As cra is single page application, you need server setting to redirect everytime to index.html,
You might want to check this link
https://www.netlify.com/blog/2020/04/07/creating-better-more-predictable-redirect-rules-for-spas/

Getting an "Access Denied" error when I reload my React app on AWS Amplify

I am working on a React app that's running on AWS Amplify. My React app is using the react-router-dom library to route to different components. After running amplify publish in the CLI, at the root of the app (obktraining.com) everything is fine in the browser, I can also route to other components in the app just fine as well. But when I refresh my browser while I am on a route (obktraining.com/menu), I get an Access Denied error message.
I have found other posts about similar issues regarding rewrites and redirects in Amplify, but the solutions given do not work for me.
Here is an image of the error:
My Amplify app rewrites & redirects :
Again, the error only displays when I refresh on a route (obktraining.com/menu or obktraining.com/drinks) not on obktraining.com. Is the issue being caused by the react-router-dom library or is it an issue with Amplify settings? I am not sure where to go from here.
I have been facing the same error since days.The error is being caused by the amplify settings. The solution is simple,
Edit your Rewrites and redirects by adding a new rule.
source address = </^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>
target address = /index.html
status = 200 (Rewrite)
Country code can be left blank
Save and try refreshing your app again. It should probably work.
use this for reference: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
Then you can just put in (as Dhruv Godambe posted above)
</^((?!.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
as the Source address and
/index.html as your target address
You can navigate to 'rewrites and redirects' in your app from AWS Amplify console and click on edit and select open text editor, and add this piece of code in your array(if present) else put the array braces around it.
{
"source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>",
"target": "/index.html",
"status": "200",
"condition": null
}
Reference: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
Reference:
https://docs.aws.amazon.com/amplify/latest/userguide/manual-deploys.html
I have faced the same problem.
I was using Manual Zip File (Compressed) download (wrong).
Here is how to deploy manually correctely:
Run this command
npm run build
Now a build folder will be created.
2. Compress the content of this folder
Not the content of the whole project.
You chnage directory to the build folder and Compress the content in side.
3. Upload that compressed file Inside the build directory
Now this should work just fine.
:)
The correct rule should be like this:
Source address: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
Target address: /index.html
Status: 200
I was getting the an Access Denied error message too. The error went away when I followed the documentation described in the answer above, but then I got the white screen problem described above too.
Reviewing the steps I noticed the auto-complete for the "Destination Address" listed in the "Rewrites and redirects" settings was /. When I tried using / as the "Destination Address" instead of /index.html I no longer got the white screen and got the expected page content.
Sharing what I found in case this helps others who are seeing a white screen after fixing the error with the rewrite rule described in the answers above. (Note as of Nov 2022 the "Rewrites and redirects" setting page uses the wording "Target Address" instead of "Destination Address".)
I have faced the same problem. I was zipping build folder, but not the contents within the zip folder.
Here is how I fixed it:
Run build command
npm run build
Now a build folder will be created inside your project directory.
Open build folder.
Compress the contents of build folder, and not build folder.
Now upload this new zip created from sub files and folders from build folder.
App will run fine on AWS Amplify.
I got the same error,
I zipped the build folder first then uploaded it and got that error,
but when I just uploaded the folder without zipping it, it worked fine !! weird!!
in my application I used the port 8080

Resources