react-router-tutorial icon indicating copy to clipboard operation
react-router-tutorial copied to clipboard

React-Router cannot GET /path #Error

Open dharnnie opened this issue 8 years ago • 3 comments

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

dharnnie avatar Nov 23 '17 12:11 dharnnie

Do you resolve it???

CharlyCheng avatar Sep 05 '18 02:09 CharlyCheng

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

tony2tones avatar Sep 18 '18 14:09 tony2tones

Even though I use HashRouter, I can't get access. Who can help me?

Apollo725 avatar Oct 12 '18 20:10 Apollo725