任何导航都未处理“导航/重置”操作
Posted
技术标签:
【中文标题】任何导航都未处理“导航/重置”操作【英文标题】: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)
如果您能建议我任何解决方案,将不胜感激。
【问题讨论】:
【参考方案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 没问题,编码愉快 :)以上是关于任何导航都未处理“导航/重置”操作的主要内容,如果未能解决你的问题,请参考以下文章
如何将 React Native 应用程序导航重置为 React Navigation 的当前屏幕
@EnableJpaRepositories 未检测到或在 spring-boot 应用程序中的任何位置都未检测到 Repository 的 @Autowired
iOS 7 UIView animateWithDuration:animations:completion: 在任何类型的转换中重置其操作