尝试导航到另一个屏幕,但遇到问题。代码如下:
Routes.js
import { Drawer } from './Drawer';
import { ItemDetailsScreen } from '../screens/ItemDetailsScreen';
enter code here
export const App = createStackNavigator(
{
Drawer: {
screen: Drawer
},
ItemDetails: {
screen: ItemDetailsScreen
}
},
{
initialRouteName: "Drawer",
headerMode: "none"
}
)
Drawer.js
export const Drawer = createDrawerNavigator(
{
Home: { screen: ItemListScreen }
},
{
navigationOptions: () => ({
drawerLockMode: 'locked-closed'
})
initialRouteName: "Home",
drawerPosition: 'left',
contentComponent: props => <SideBar {...props} />
}
)
通过调用以下方法尝试导航“ ItemDetailsScreen”时,它会向我显示错误
onItemPress(item) {
const navigateAction = NavigationActions.navigate({
routeName: 'ItemDetailsScreen',
params: {item: item}
})
this.props.navigation.dispatch(navigateAction)
}
错误是:
无法读取未定义的属性“ dispatch”