2016-02-11 153 views
1

這是我的反應路由器配置。我有一個主要組件和子組件。反應路由器編程導航不起作用

var Router = ReactRouter.Router; 

var Route = ReactRouter.Route; 

var transitionStates = CommonConstantsMixin.transitionStates; 

var routes=(

    <Route path="/" component={OnboardModalComponent}> 
     <Route path={transitionStates.ERROR} component={ErrorComponent}/> 
     <Route path={transitionStates.SETUP_SELECTION} component={SetupSelectionComponent}/> 
     <Route path={transitionStates.KEY_ENTRY} component={KeyEntryComponent}/> 
     <Route path="*" component={ErrorComponent}/> 
    </Route> 

); 
ReactDOM.render(<Router routes={routes} history={ReactRouter.hashHistory}></Router>, document.getElementById('onboard-container')); 

我OnboardModalComponent:

var OnboardModalComponent = React.createClass({ 

render: function(){ 
return (

      <div className="fp-modal-body"> 
       {this.props.children}    
      </div> 

); 
} 
}); 

,並在我的反應建立成分正在試圖像導航,

var SetupSelectionComponent = React.createClass({ 

contextTypes: { 
router: React.PropTypes.object.isRequired 
}, 
enterKey: function(){ 
    OnboardActions.changeFlow(this.onboardFlows.ENTER_KEY); 
    this.context.router.push("/"+this.transitionStates.KEY_ENTRY); 
}, 
render: function() { 
    return (

    <div className="fp-modal-body-inner" style={{display:'none'}}> 
    ............................... 
    </div> 

); 
} 
}); 

什麼是錯的代碼?爲什麼反應路由不起作用?

回答