I use React-Route and expres It is necessary to give the file public / index.html on all paths. On the server, the code is:
//устанавливаем папку public за статику. app.use(express.static('public')); //путь "/" app.get('/', (req, res) => { res.sendFile( __dirname + '/public/index.html' ); }); //путь "/signin" app.get('/signin', (req, res) => { res.sendFile( __dirname + '/public/index.html' ); }); React-Router on client:
<Router history={browserHistory}> <Route path="/" component={Home} /> <Route path="/signin" component={LoginForm} /> </Router> When you start the server, the {Home} component is displayed perfectly, but you can get into the "/ signin" path; you can only get to the {loginForm} component via the link
<Link to="/signin"> signin </Link> which is in the Home component.
The problem is that if you hit the path /signin reload the page using F5, we get the following error:
Error: ENOENT: no such file or directory, stat 'C: \ Web development \ server \ public \ index.html' at Error (native)
Express requires static, but I already added the public folder on the server. How to solve a problem?