Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

React-Router cannot GET /path #Error #330

Open
dharnnie opened this issue Nov 23, 2017 · 3 comments
Open

React-Router cannot GET /path #Error #330

dharnnie opened this issue Nov 23, 2017 · 3 comments

Comments

@dharnnie
Copy link

dharnnie commented Nov 23, 2017

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

@CharlyCheng
Copy link

Do you resolve it???

@tony2tones
Copy link

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

@Apollo725
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants