发布于 4年前

禁用react-navigation导航的返回按钮

对于react-navigation >=1.0.0-beta.9可以设置headerLeft为null,这样返回按钮会隐藏。

navigationOptions:  {
    title: 'MyScreen',
    headerLeft: null
}

另外也可以清除导航堆栈,

import { NavigationActions } from 'react-navigation';

resetNavigation(targetRoute) {
  const resetAction = NavigationActions.reset({
    index: 0,
    actions: [
      NavigationActions.navigate({ routeName: targetRoute }),
    ],
  });
  this.props.navigation.dispatch(resetAction);
}

resetNavigation接收目标路由作为参数,在跳转前的页面调用resetNavigation(),跳转到目录路由后将会重置,清空导航堆栈。

©2020 edoou.com   京ICP备16001874号-3