React Router Error - Cannot GET [Page Name]

- 1 answer

Ad

As I am digging into React I am finding a need for the router. I am following along with Wes Bos' video series but am hitting a snag when I try to access any route other than my root.

import ReactRouter from 'react-router';
var Router = require('react-router').Router;
var Route = require('react-router').Route;
var Link = require('react-router').Link;
var createBrowserHistory = require('history/lib/createBrowserHistory');

Then my router

var routes = (
  <Router history={createBrowserHistory()}>
    <Route path="/" component={LoginPage} />
    <Route path="/dashboard" component={Dashboard} />
    <Route path="/search" component={SearchPage} />
    <Route path="/details" component={DetailsPage} />
    <Route path="*" component={LoginPage} />
  </Router>
);
ReactDOM.render(routes, document.getElementById('content'));

However, if I go to localhost:3000/dashboard I am given the error:

Cannot GET /dashboard

Any advice?

Ad

Answer

Ad

Add this to webpack.config.js

  devServer: {
      historyApiFallback: true
  }
Ad
source: stackoverflow.com
Ad