【问题标题】:The action 'Navigation/RESET' was not handled by any navigation任何导航都未处理“导航/重置”操作
【发布时间】:2020-11-27 19:35:20
【问题描述】:

我遇到了一个错误。当我尝试重置屏幕导航堆栈时,我收到此错误The action 'Navigation/RESET' was not handled by any navigation

我重置导航的代码是:

 let resetAction = StackActions.reset({
       key: null,
       index: 0,
       actions: [
         NavigationActions.navigate({ routeName: 'ScreenName' })
       ]
    })
 this.props.navigation.dispatch(resetAction)

如果您能建议我任何解决方案,将不胜感激。

【问题讨论】:

    标签: react-native react-redux react-navigation


    【解决方案1】:

    在 5.x 版本中,重置导航的方式发生了变化。你可以使用:

    import { StackActions } from '@react-navigation/native';
    this.props.navigation.dispatch(
      StackActions.popToTop()
    );
    

    从堆栈中弹出所有页面重定向,然后返回第一个屏幕。 (view it on expo)

    或者你可以使用:

    import { CommonActions } from '@react-navigation/native';
    
    navigation.dispatch(
      CommonActions.reset({
        index: 1,
        routes: [
          { name: 'Home' },
          {
            name: 'Profile',
            params: { user: 'jane' },
          },
          ...
        ],
      })
    );
    

    将导航状态重置为初始状态。

    这是一个live demo on snack expo(使用android标签,从主页转到details页面,然后page 3,然后按重置。您可以看到它现在在主页上,如果您按返回,它将退出。 )(popToTop 的代码在第 44 行)

    文档:pop to top actionreset action

    Ps:如果你没有使用 5.x 版本,首先确保你有一个名为 ScreenName 的路由(因为你使用的是:routeName: 'ScreenName',如果没有修复它,请尝试其他代码重置,例如:here)

    【讨论】:

    • @ManiKantTiwari 没问题,编码愉快 :)
    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2015-02-24
    相关资源
    最近更新 更多