问题
I have a webapp with ReactJS as frontend and dropwizard java backend.
all methods of REST API backend are in the path
http://localhost:8080/api
The react have routes like /login /signup
when I run the reactJs frontend separately the routes
http://localhost:3000/login
http://localhost:3000/signup
can be navigated directly.
when I run the backend with fronted by using configurable-assets the main page works and in main page I have link to /login, /signup component which also works as expected. The problem in when I directly access
http://localhost:8080/login
http://localhost:8080/signup
it doesn't work and says 404 not found.
investigating further I found that in the react build generated directory if I add directory like login signup and have index.html file over there its able to render that index.html file.
My question is what is the recommended way of solving this
- one way would be to run the frontend separately
- other would be to change the backend route somehow to point it to React routes
Any suggestions are highly appreciated.
来源:https://stackoverflow.com/questions/57663407/reactjs-handling-routing-while-integrating-with-api