2016-03-31 20 views
6

programlama işe yaradı böylece this.props.history.push('/new-path'); gibi farklı bir sayfaya gitmek için çalışıyordu itiraz edildi, ancak söyleyerek konsolda bir kullanımdan kaldırılması uyarı var:this.props.history (tepki-yönlendirici)

burada

Warning: [react-router] props.history and context.history are deprecated. Please use context.router. bu konuda daha fazla


https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#changes-to-thiscontext Sonrasında ben çok this.context.router.push('/new-path') gibi bu yeni yöntemi kullanmaya çalıştı ama bu doğru bir yaklaşım olarak görünmemektedir.

+0

Muhtemelen ilgili: http://stackoverflow.com/questions/35213446/react- yönlendirici-bu-bağlam yönlendirici-itme-not-remount-bileşeni yapar –

cevap

13

Yönlendiriciyi contextType olarak tanımlamayı unutabilir misiniz? Sahip varsayarsak bileşeni gibi: aşağıdaki gibi contextTypes tanımlamak zorunda

class YourComponent extends React.Component { 
     render() { 
     return <div></div>; 
     } 
} 

sağ bileşeni altında:

YourComponent.contextTypes = { 
    router: React.PropTypes.object.isRequired 
};