React router only works with root path

旧时模样 提交于 2019-12-04 06:15:59

问题


Only root route works. /about, /home shows "Cannot GET /home" in browser. If i replace each route path with "/" then the corresponding component is rendering. But there seems to be problem when i try to render certain route eg /home.


回答1:


You have to configure your server to work with Router.HistoryLocation -- that is, it needs to always serve your index.html page regardless of the route.

app.get('*', function (req, res) {
  res.render('index');
});

Check out the docs here: React Router Docs - HistoryLocation



来源:https://stackoverflow.com/questions/32276514/react-router-only-works-with-root-path

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