ReactJs handling routing while integrating with API

血红的双手。 提交于 2019-12-11 06:17:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!