React-Router cannot GET /path #Error
I am not getting the desired result from using react-router-dom for routing in my react application. Here is the issue.
Error:
cannot GET /path
I get this error when I try to access a route other than '/'.
app.js code
import {BrowserRouter, Route, browserHistory} from 'react-router-dom'; class App extends Component{ render(){ return( <BrowserRouter history={browserHistory}> <div> <Route exact path="/" component={Login}/> <Route path="/about" component={About}/> </div> </BrowserRouter> ); } } render(<App/>, document.getElementById("root"));
When I try to access /about, I get that response from the browser.
I have edited my config as seen in other issues. I added
devServer:{ contentBase: DIST_DIR, historyApiFallback: true }
and
webpack.output.publicPath: '/'
Nothing changes. react-router v4.2.2
Do you resolve it???
I came across the same problem, if you have a server that responds to requests and a HashRouter if you are using a static file server. Instead of using BrowserRouter use HashRouter its not the perfect fix, but should solve the cannot GET "/path" error. be sure to import HashRouter from 'react-router-dom'
render() {
return (
<div>
<HashRouter>
<Blog />
</HashRouter>
</div>
);
}
source: https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/guides/basic-components.md
Even though I use HashRouter, I can't get access. Who can help me?