简体   繁体   中英

Why does react-routing not work directly in the browser?

I am using react-router 2.0 in my universal react app. Navigation trough the Link component works but when I paste the url manually nothing happens(browser hangs). How can I fix this issue? This is the router code:

<Route path="/" component={App}>
  { /* Home (main) route */ }
  <IndexRoute component={Home}/>

  { /* Routes requiring login */ }
  <Route onEnter={requireLogin}>
    <Route path="chat" component={Chat}/>
    <Route path="loginSuccess" component={LoginSuccess}/>
  </Route>

  { /* Routes */ }
  <Route path="about" component={About}/>
  <Route path="login" component={Login}/>
  <Route path="pagination" component={Pagination}/>
  <Route path="survey/:user" component={Survey}/>
  <Route path="widgets" component={Widgets}/>
  <Route path="search" component={Search}/>
  <Route path="make/model/:id" component={Details}/>
  { /* Catch all route */ }
  <Route path="*" component={NotFound} status={404} />
</Route>

try this in your routes

add "/" in all routes like this

<Route path="/about" component={About}/>

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