나는 React를 배우기 위해 일하고있다. 이 샘플 프로젝트는 React 0.13.3 및 Reaction-Router 0.13.3과 함께 사용하도록 설계되었습니다. 나는 react 15.4.1과 react-router 3.0.0을 사용하고있다.React Router 페이지 탐색하기
샘플 프로젝트는 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 규칙을 사용했습니다. 나는 약 페이지로 이동하려면 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'));
나는 데 문제가 있습니다 : 여기에 내가 지금까지 가지고있는 것입니다.
나는 뭔가를 놓쳤다 고 확신한다. 나는 무엇을 잘못하고있을 것인가?