2016-08-17 10 views
0

관리자가 편집 버튼을 클릭하여 제품 세부 정보를 수정할 수있는 제품 페이지를 만들려고 시도 중이지만 관리자가 아직 변경하지 않은 변경 사항을 페이지에 남겨 두려고하면 저장하면 사용자가 저장하지 않고 페이지를 나가기를 원할 것입니다.React Redux 내비게이션 확인

관리자가 클릭 할 때 Product.js에서 사용하는 내 ProductForm.js에 현재있는 항목이 있습니다.

import { browserHistory } from 'react-router'; 
    componentWillReceiveProps() { 
    browserHistory.listenBefore(location => { 
     console.log(location); 
     return 'Are you sure you want to leave the page without saving?'; 
    }); 
    } 

다음 코드로 문제는 제품 페이지에없는 경우에도, 사용자가 편집 양식을 열 때이 확인 메시지가 모든 페이지의 전환을 보여주고 있다는 점이다.

다음 스켈레톤을 사용하고 있습니다. https://github.com/erikras/react-redux-universal-hot-example

는이 같은 수신기를

답변

1

취소 할 수 있습니다 :

import { browserHistory } from 'react-router'; 
    componentWillReceiveProps() { 
    const cancelListner = browserHistory.listenBefore(location => { 
     console.log(location); 
     cancelListner(); 
     return 'Are you sure you want to leave the page without saving?'; 
    }); 
    }