Man*_*ari 4 react-native react-redux react-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)
Run Code Online (Sandbox Code Playgroud)
如果您能建议我任何解决方案,我将非常感激。
在版本 5.x 中,重置导航的方式发生了变化。您可以使用 :
import { StackActions } from '@react-navigation/native';
this.props.navigation.dispatch(
StackActions.popToTop()
);
Run Code Online (Sandbox Code Playgroud)
从堆栈中弹出所有页面重定向,然后返回到第一个屏幕。(在博览会上查看)
或者您可以使用:
import { CommonActions } from '@react-navigation/native';
navigation.dispatch(
CommonActions.reset({
index: 1,
routes: [
{ name: 'Home' },
{
name: 'Profile',
params: { user: 'jane' },
},
...
],
})
);
Run Code Online (Sandbox Code Playgroud)
将您的导航状态重置为初始状态。
这是零食博览会的现场演示(使用android选项卡,从主页转到details页面,然后page 3按重置。您可以看到它现在在主页上,如果您按返回,它将退出。)(代码为popToTopon第 44 行)
Ps:如果您没有使用版本 5.x ,请首先确保您有一个名为的路由ScreenName(因为您正在使用 : routeName: 'ScreenName',如果它没有修复它,请尝试其他代码来重置,例如:here)
| 归档时间: |
|
| 查看次数: |
13904 次 |
| 最近记录: |