2016-12-09 8 views
0

私はリアクトを学ぶために働いています。このサンプルプロジェクトは、React 0.13.3およびreact-router 0.13.3で使用するように設計されています。私は反応15.4.1と反応ルータ3.0.0を使用していますリアクタールーターページへのナビゲーションを確認

サンプルプロジェクトはwillTransitionToを使用してユーザーにページへのナビゲートを許可する前に簡単な確認を行います。ここにコードです:

var About = React.createClass({ 
    statics: { 
    willTransitionTo: function(transition, params, query, callback) { 
     if (!confirm('Are you sure you want to read a page that\'s this boring?')) { 
     transition.about(); 
     } else { 
     callback(); 
     } 
}, ... 

私が使用している反応ルータのバージョンで知っている、上記はもう機能しません。したがって、auth-flowの例では、on the react router docs pageというコードでは、onEnterの規約を使用するようにコードを変換しました。ここで私がこれまで持っているものです。

function confirmTransition(nextState, replace){ 
    if(comfirm('Are you sure you want to read a page that\'s this boring?')){ 
     replace({ 
      pathname: '/about', 
      state: {nextPathname: nextState.location.pathname} 
     }); 
    } 
} 

ReactDOM.render((
    <Router history={hashHistory}> 
     <Route path="/" component={require('./components/app')}> 
      <IndexRoute component={require('./components/homePage')} /> 
      <Route path="/authors" component={require('./components/authors/authorPage')} /> 
      <Route path="/about" component={require('./components/about/aboutPage')} /> 
      <Redirect from="about-us" to="about" /> 
      <Route path='*' component={require('./components/notFoundPage')} onEnter={confirmTransition}/> 
     </Route> 
    </Router> 
), document.getElementById('app')); 

私がいる問題は、私はおよそページに移動しようとすると、フォーカス取得時には発生しませんです。

私は何かが不足していると確信しています。何が間違っているのでしょうか?

答えて

0

私は...知的ではない。私は間違ったルートにonEnterを配置していることが分かった。

ありがとうございました。

関連する問題