反应导航重置并重定向到主屏幕
react navigation reset and redirect to home screen
我想在用户登录后重置导航然后我们将重定向到主页我试过这个
const Root = StackNavigator({
Unauthorized: { screen: UnAuthorized },
Authorized: { screen: Authorized },
}, {
headerMode: 'screen',
navigationOptions: {
header: null
}
});
const Authorized = DrawerNavigator({
Home: { screen: Home }
});
const UnAuthorized = StackNavigator({
Splash: { screen: Splash },
Login: { screen: Login },
});
await axios.post(url+'rest_users/login',user)
.then(function (response) {
dispatch({
type: LOGGED_IN,
payload: response.data
});
const resetNavigator = NavigationActions.reset({
index: 0,
key: null,
actions: [
NavigationActions.navigate({
routeName: 'Authorized',
action: [
NavigationActions.navigate({routeName: 'Home'})]
})
],
});
dispatch(resetNavigator);
导航在日志中显示重置,但我没有看到任何屏幕移动变化。请帮助我哪里出错了
看起来,您正在使用 Redux 的调度方法,而不是 React-Navigation 来调度您的 resetAction。
你应该做的是将导航道具从你的组件传递到你需要调度 resetAction 的地方,然后调用 navigation.dispatch(resetAction)
我想在用户登录后重置导航然后我们将重定向到主页我试过这个
const Root = StackNavigator({
Unauthorized: { screen: UnAuthorized },
Authorized: { screen: Authorized },
}, {
headerMode: 'screen',
navigationOptions: {
header: null
}
});
const Authorized = DrawerNavigator({
Home: { screen: Home }
});
const UnAuthorized = StackNavigator({
Splash: { screen: Splash },
Login: { screen: Login },
});
await axios.post(url+'rest_users/login',user)
.then(function (response) {
dispatch({
type: LOGGED_IN,
payload: response.data
});
const resetNavigator = NavigationActions.reset({
index: 0,
key: null,
actions: [
NavigationActions.navigate({
routeName: 'Authorized',
action: [
NavigationActions.navigate({routeName: 'Home'})]
})
],
});
dispatch(resetNavigator);
导航在日志中显示重置,但我没有看到任何屏幕移动变化。请帮助我哪里出错了
看起来,您正在使用 Redux 的调度方法,而不是 React-Navigation 来调度您的 resetAction。
你应该做的是将导航道具从你的组件传递到你需要调度 resetAction 的地方,然后调用 navigation.dispatch(resetAction)