2

my react app is working locally but after the deploy, I faced the problem when I press any button there is no problem but if I want to refresh I see that problem "404 - File or directory not found."

I found this solution: https://github.com/ReactTraining/react-router/blob/v3/docs/guides/Histories.md#browserhistory

Configure Your Server

"Your server must be ready to handle real URLs. When the app first loads at / it will probably work, but as the user navigates around and then hits refresh at /accounts/23 your web server will get a request to /accounts/23. You will need it to handle that URL and include your JavaScript application in the response."

But I don't know how can I do this I try something but it doesn't work

ilkerkaran
  • 4,214
  • 3
  • 27
  • 42
kastisk
  • 31
  • 2
  • 3
  • if you are serving with nginx redirect all requests to index.html, that will fix the issue. in that way your app will get all the requests – warl0ck May 30 '19 at 07:27

2 Answers2

1

TRY

  1. npm run build, this will create build folder inside your project root folder
  2. if you want to deploy to remote server just transfer that build folder.
  3. npx serve -s build on windows, if you are using mac kindly see if it is still npx.
  4. then try to refresh every path of it

hope this works, happy coding.

Aljohn Yamaro
  • 2,629
  • 25
  • 22
0

Since the server cannot find the static content in the directory (i.e. not found the file /tomcat/accounts/23), it will give you 404 unless you have additional route handling.

In React routing I think you can try with HashRouter

See more details here:

https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/HashRouter.md

HashRouter vs BrowserRouter

Alanw
  • 24
  • 2