1
當我按下Backbutton時,它會切換回前一個屏幕,但也關閉應用。我已經嘗試添加event.preventDefault(),但它不能解決我的問題。BackAndroid - 應用仍然關閉
componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress',() => {
this.goBack();
})
}
goBack() {
this.props.actions.goBack();
}
//Reducer
export default function navReducer(state = initialState, action = {}) {
switch(action.type) {
case types.OPEN:
return {
scenes: [
...state.scenes,
{key: action.key, name: action.name}
]
};
case types.BACK:
if(state.scenes.length > 1) {
return {
scenes: state.scenes.slice(0, state.scenes.length - 1)
}
} else {
console.log('Error')
};
default:
return state;
}
}