导航/重置操作未由任何导航处理 [英] The action 'Navigation/RESET' was not handled by any navigation
本文介绍了导航/重置操作未由任何导航处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一个错误。当我尝试重置屏幕导航堆栈时,收到此错误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)
如果您能给我任何解决方案,我们将不胜感激。
推荐答案
在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
,然后按重置。您现在可以在主页上看到它,如果您按BACK,它将退出。)(popToTop
的代码在第44行)
单据:pop to top actionreset action
ps:如果您使用的不是5.x版本,请首先确保您有一个名为ScreenName
的路由(因为您使用的是:routeName: 'ScreenName'
,如果无法修复,请尝试使用其他代码进行重置,如:here)
这篇关于导航/重置操作未由任何导航处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文