简体   繁体   中英

Cannot get route in React Router v4

When I go to localhost:8080/ and refresh the expected page is hit and it constantly renders the correct page. If I click on a link it goes to the correct page but then on refresh I get the CANNOT GET error message

This is some of the code:

    <div>
      <Route strict path="/" component={Header} />
      <Route strict path="/quizzes" component={QuizList} />
    </div>

Just put this line into my webpack config as well:

  devServer: {
    historyApiFallback: true
  },

I'm confused because it renders the correct page just on refresh it cannot get it (except for the homepage ( / ) url).

Your problem is on the server side. You didn't provide the code, but most likely you have the only endpoint defined at http://localhost:8080/ . You will need a well configured server to host application using browser history such as react-router. You can take a look at this guide for example: https://medium.com/@patriciolpezjuri/using-create-react-app-with-react-router-express-js-8fa658bf892d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM