rosnk
rosnk

Reputation: 1098

React router only works with root path

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.

enter image description here

enter image description here

enter image description here

Upvotes: 0

Views: 3132

Answers (1)

BradByte
BradByte

Reputation: 11093

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

Upvotes: 1

Related Questions