0
我已經使用react-navigation和點擊android中的硬件後退按鈕,我回到以前的組件,但componentWillMount不會被調用。我如何確保componentWillMount被調用?雖然從反應導航回來componentWillMount不會被調用
我已經使用react-navigation和點擊android中的硬件後退按鈕,我回到以前的組件,但componentWillMount不會被調用。我如何確保componentWillMount被調用?雖然從反應導航回來componentWillMount不會被調用
@bumbur的這個答案對您有幫助嗎?它定義了一個全局變量,用於跟蹤導航狀態是否已更改。你可以插入一段代碼,看看你是否在你感興趣的特定標籤中。這樣你可以觸發對componentWillMount()的調用?
如果你不想使用終極版,這是你可以存儲有關當前路由全球 信息,這樣你就可以同時檢測到標籤的變化 也告訴哪個選項卡現在是活動的。
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);
}}
/>;
可能重複https://stackoverflow.com/questions/39514572/react-router-redux-navigating-back-doesnt-call-componentwillmount –