0
그래서 필자는 this 튜토리얼을 따라 내가 필요한 것을 적용했습니다.네이티브, 리펙트 네비게이션 통합 문제가 정의되지 않았습니다. 객체가 아닙니다. getStateForAction
다른 답변을 확인했지만 누락 된 부분을 확실히 확인할 수 없습니까? 검색 엔진
는 오류 : 미정 오브젝트 라우터 아니다
App.js
import React, {Component} from 'react';
import {createStore, combineReducers, applyMiddleware} from 'redux'
import {Provider, connect} from 'react-redux'
import reducers from './reducers'
import {View} from 'react-native'
import ReduxNavigation from './components/Navigation/ReduxNavigation'
const initialState = ReduxNavigation.router.getStateForAction(ReduxNavigation.router.getActionForPathAndParams('AddItems'));
const navReducer = (state = initialState, action) => {
const newState = ReduxNavigation.router.getStateForAction(action, state)
return newState || state
}
const store = createStore(
combineReducers({
...reducers,
nav: navReducer,
})
)
export default class App extends Component {
render() {
return (
<Provider store={store}>
<ReduxNavigation/>
</Provider>
)
}
}
ReduxNavigation getStateForAction
:import React from 'react'
import * as ReactNavigation from 'react-navigation'
import { connect } from 'react-redux'
import PrimaryNav from './PrimaryNav'
// here is our redux-aware our smart component
function ReduxNavigation (props) {
const { dispatch, nav } = props
const navigation = ReactNavigation.addNavigationHelpers({
dispatch,
state: nav
})
return <PrimaryNav navigation={navigation} />
}
const mapStateToProps = state => ({ nav: state.nav })
export default connect(mapStateToProps)(ReduxNavigation)
PrimaryNav :
import React from 'react'
import {StackNavigator, DrawerNavigator} from 'react-navigation'
import AddItemsWrapper from '../AddItemsWrapper'
import {Text} from 'react-native'
const noTransitionConfig =() => ({
transitionSpec: {
duration: 0,
timing: Animated.timing,
easing: Easing.step0
}
})
const DrawerStack = DrawerNavigator({
screen: {screen: AddItemsWrapper}
}, {
gesturesEnabled: false,
})
const drawerButton = (navigation) =>
<Text
style={{padding: 5, color: 'white'}}
onPress={() => {
// Coming soon: navigation.navigate('DrawerToggle')
// https://github.com/react-community/react-navigation/pull/2492
if (navigation.state.index === 0) {
navigation.navigate('DrawerOpen')
} else {
navigation.navigate('DrawerClose')
}
}
}>Menu</Text>
const DrawerNavigation = StackNavigator({
DrawerStack: {screen: DrawerStack}
}, {
headerMode: 'float',
navigationOptions: ({navigation}) => ({
headerStyle: {backgroundColor: '#4C3E54'},
title: 'Welcome!',
headerTintColor: 'white',
gesturesEnabled: false,
headerLeft: drawerButton(navigation)
})
})
// Manifest of possible screens
const PrimaryNav = StackNavigator({
drawerStack: { screen: DrawerNavigation }
}, {
// Default config for all screens
headerMode: 'none',
title: 'Main',
initialRouteName: 'loginStack',
transitionConfig: noTransitionConfig
})
export default PrimaryNav
추측. App 클래스 render에서'View'를 제거하고'Provider'의'ReduxNavigation' 직접 자식을 만들 수 있습니까? – bennygenel
네! 영향을주지 않습니다. –
반응 탐색 문서에는'initialState' 생성이 있습니다. 어쩌면 당신이 그것을 놓치고 있기 때문에. [this] (https://reactnavigation.org/docs/guides/redux#Redux-Integration)를 확인하십시오. – bennygenel