Redux with React-Navigation嵌套导航器:TypeError:undefined不是对象(评估'nextState.routes.forEach')...

问题描述 投票:0回答:1

试图在redux商店中获取导航状态并遇到问题。我很接近,但试图理解这个错误意味着什么:TypeError:undefined不是一个对象(评估'nextState.routes.forEach')

导航根呈现功能中有一个authcheck,用于确定要使用的导航状态。选择了正确的,但是当它试图使用它时,我会遇到上面的错误。

AppNavigator内部是两个不同的导航路径,它们是分开的。

-AppNavigator
--SignedInNavigator
---TabBar
--SignedOutNavigator
---StackNavigator

这是我收到错误时使用的导航对象。

[exp] Object {
[exp]   "index": 0,
[exp]   "routes": Array [
[exp]     Object {
[exp]       "action": Object {
[exp]         "routeName": "Home",
[exp]         "type": "Navigation/NAVIGATE",
[exp]       },
[exp]       "key": "Init-id-1513449605995-1",
[exp]       "routeName": "SignedOut",
[exp]       "type": undefined,
[exp]     },
[exp]   ],
[exp] }

render() {
   const { navigationState, dispatch, isLoggedIn } = this.props;
   const state = isLoggedIn ? navigationState.stateForLoggedIn : navigationState.stateForLoggedOut;

   return (
       <AppNavigator navigation={addNavigationHelpers({ dispatch, state })} />
   );
}

可以提供更多代码,如必要时使用的reducer。唯一的原因我不是因为减速器正在给我我现在想要的信息,但显然它没有被消化得很好。任何帮助表示赞赏。谢谢!

react-native react-redux react-navigation
1个回答
0
投票

我也是新人,但这对我有用。以下是两个单独的文件....

ReduxNavigation.js

    import React from 'react'
import * as ReactNavigation from 'react-navigation'
import { connect } from 'react-redux'
import AppNavigation from './AppNavigation'

// here is our redux-aware our smart component
function ReduxNavigation (props) {
  const { dispatch, nav } = props
  const navigation = ReactNavigation.addNavigationHelpers({
    dispatch,
    state: nav
  })

  return <AppNavigation navigation={navigation} />
}

const mapStateToProps = state => ({ nav: state.nav })
export default connect(mapStateToProps)(ReduxNavigation)

AppNavigation.js

import { StackNavigator } from 'react-navigation'
import { Animated, Easing } from 'react-native'
import LoginScreen from '../Containers/LoginScreen'
import LaunchScreen from '../Containers/LaunchScreen'
import HomeScreen from '../Containers/HomeScreen'
import SignUpScreen from '../Containers/SignUpScreen'
import SettingsScreen from '../Containers/SettingsScreen'
import VehicleCreateScreen from '../Containers/VehicleCreateScreen'
import styles from './Styles/NavigationStyles'

// Manifest of possible screens
const PrimaryNav = StackNavigator({
  LoginScreen: { screen: LoginScreen },
  LaunchScreen: { screen: LaunchScreen },
  HomeScreen: { screen: HomeScreen },
  SignUpScreen: { screen: SignUpScreen },
  SettingsScreen: { screen: SettingsScreen },
  VehicleCreateScreen: { screen: VehicleCreateScreen }
}, {
    // Default config for all screens
    headerMode: 'none',
    initialRouteName: 'LaunchScreen',
    navigationOptions: {
      headerStyle: styles.header
    },
    transitionSpec: {
      duration: 0,
      timing: Animated.timing,
      easing: Easing.step0,
    },
  },

  transitionConfig = () => ({
  }),


)

export default PrimaryNav
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.