2017-09-18 2 views
0

반응 탐색을 사용하고 android에서 하드웨어 다시 버튼을 클릭하면 이전 구성 요소로 돌아 오지만 componentWillMount는 호출되지 않습니다. componentWillMount가 호출되도록하려면 어떻게해야합니까?반응 탐색 구성 요소에서 돌아 오는 동안 WeillMount가 호출되지 않습니다.

+0

수 https://stackoverflow.com/questions/39514572/react-router-redux-navigating-back-doesnt-call-componentwillmount 중복 –

답변

0

@bumbur의 답변으로 도움이됩니까? 탐색 상태가 변경되었는지 여부를 추적하는 전역 변수를 정의합니다. 관심있는 특정 탭에 있는지 코드 조각을 삽입하여 componentWillMount() 호출을 트리거 할 수 있습니까?

당신이 REDUX를 사용하지 않으려면

, 이것은 당신이 현재 경로에 대한 전 세계적 정보를 저장할 수 있습니다, 그래서 당신은 탭 변화 을 감지하고도 현재 활성화 된 탭 말할 수있는 두 방법이다.

https://stackoverflow.com/a/44027538/7388644

export default() => <MyTabNav 
    ref={(ref) => { this.nav = ref; }} 
    onNavigationStateChange={(prevState, currentState) => { 
     const getCurrentRouteName = (navigationState) => { 
     if (!navigationState) return null; 
     const route = navigationState.routes[navigationState.index]; 
     if (route.routes) return getCurrentRouteName(route); 
     return route.routeName; 
    }; 
    global.currentRoute = getCurrentRouteName(currentState); 
    }} 
/>;