2017-04-25 42 views
0

我有這樣路線不COMMITED反應

render(
    <Provider store={store}> 
     <Router history={history}> 
     <Route path='/' component={TopContainer}> 
      <IndexRoute component={Login} /> 
      <Route path='main' component={MainContainer} /> 
      <Route path='second' component={SecondContainer} /> 
     </Route>   
    </Router> 
    </Provider>, 
    document.getElementById('root') 
) 

的路線,我喜歡跳到第二和使用

import { browserHistory } from 'react-router'; 
browserHistory.push('/#second'); 

The result was that the browser address field was filled with  
"http://localhost:3000/#second" but the page did not move-to/show 
"http://localhost:3000/#second" and still stay at the same page. 
Now, if I hit enter key on the browser address field it then 
show/move-to the right page (http://localhost:3000/#second). 

什麼問題嗎?

感謝

+0

爲什麼你有之前''#'秒'? – azium

回答

1

#是不是URL的一部分。它是由您正在使用的history添加的。此外,您正在使用browserHistory推送,但不會將其用作應用的history

進行這些更改

render(
    <Provider store={store}> 
     <Router history={browserHistory}> 
     <Route path='/' component={TopContainer}> 
      <IndexRoute component={Login} /> 
      <Route path='main' component={MainContainer} /> 
      <Route path='second' component={SecondContainer} /> 
     </Route>   
    </Router> 
    </Provider>, 
    document.getElementById('root') 
) 

變化historybrowserHistory

import { browserHistory } from 'react-router'; 
browserHistory.push('/second'); 

然後用這個推到second頁面

+0

酷!有效。謝謝! –