I have a built using create-react-app and hosted in netlify.
I created a file called _redirects in folder ' public ', but it did not work. The redirect is not happening.
/* /index.html 200
I tried change the package.json :
"scripts": {
....
"build": "react-scripts build && echo '/* /index.html 200' | cat >build/_redirects ",
...
}
I tried create a file /netlify.toml on the root (same level as package.json)
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
force = false
I read this stackoverflow question and I tried everything: Catch all redirect for create-react-app in netlify
Way I'm deploying on netlify - Image
Page: https://apuro-branch-main.netlify.app/
I'm testing the following direct link: https://apuro-branch-main.netlify.app/login
I tested putting in new branch and all files in the root folder (instead of inside a folder) and it worked.
I think that (/* /index.html 200) doesn't work if the deploy is not performed in the root directory (in my case, I did it inside a folder called apuro-frontend/).
So, I've already discovered that all my difficulty is related to the deployment inside a folder (apuro-frontend/). Although I understand the problem now, I still couldn't find a solution for this specific case.
Finally I managed to solve the problem!
I believe that the deploy was storing some cache that prevented the correct redirection.
It worked with:
/* /index.html 200
I had to re-link the deploy (I also tried clearing the cache using the 'Clear cache and retry deploy' command). But it worked even after I did the following steps:
I selected the same repository I was using and put in the same commands, somehow this time it worked
This stackoverflow question helped me: netlify deploy failed: git ref refs/heads/master does not exist or you do not have permission
I had another problem, which I solved following the steps of the best answer and ended up solving both problems at once.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.