My app is deployed (npm run build
) on a Ubuntu server.
I'm using a Router in my App and when clicking on a link (i.e contact-us), it's working - user is redirected to the page.
But if I'm trying to access to the contact-us page directly (http://my_ip/contact-us), I get a 404 response.
Note: If I add a /#/ to the url, it does work! i.e http://my_ip/#/contact-us.
Some code:
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import history from './history';
render() {
return (
<div className="page">
<Router history={history}>
<Header />
<Switch>
<Route path="/combination/:some_id" exact component={SomePage} />
<Route path="/" exact component={Home} />
<Route path="/contact-us" exact component={ContactUs} />
</Switch>
</Router>
</div>
)
}
History.js:
import { createBrowserHistory } from 'history';
export default createBrowserHistory();
Update The problem was Nginx configuration: Adding the following line solved it.
try_files $uri $uri/ /index.html;
But now the problem is for the first Route (SomePage),
I just see a blank page! No error 404. what does it mean?