2016-06-18 10 views
6

sto usando la cronologia del browser e qui è il mio codice in routes.jscome risolvere il problema "il router non ha più un valore predefinito per la cronologia della storia di hash"?

export default (
    <Router history={browserHistory}> 
    <Route path="/" component={Main}> 
     <Route path="home/:username" component={Home}> 
     <IndexRoute component={HomeContent}></IndexRoute> 
     <Route path="widget/:second" component={Widget}></Route> 
     <Route path="email/:second" component={Email}> 
      <Route path="compose" component={ComposeEmail}></Route> 
      <IndexRoute component={CheckEmail}></IndexRoute> 
     </Route> 
     <Route path="social/:second" component={Social}></Route> 
     <Route path="calendar/:second" component={Calendar}></Route> 
     </Route> 
     <IndexRoute component={Login}></IndexRoute> 
    </Route> 
    </Router> 
); 

e ho usato this.context.router.push ('/') per effettuare una navigazione. e non ho idea del motivo per cui questo avviso viene visualizzato nella mia console?

"Warning: [react-router] `Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead." 

ho già letto la documentazione a https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#no-default-history ma non aiuta.

ho apprezzato qualsiasi aiuto :)

+0

È possibile aggiornare questo snippet di codice per includere l'istruzione 'import' o' require' per 'react-router'? – sighrobot

risposta

0

È necessario utilizzare hashHistory invece di browserHistory. Considerando che stai utilizzando la sintassi import puoi importare hashHistory da react-router in sostituzione di browserHistory.

import { hashHistory, Router, ... } from 'react-router'; 

const history = new hashHistory(); 

export default (
    <Router history={history}> 
    ... 
    </Router> 
); 
Problemi correlati