【发布时间】:2020-07-04 15:03:39
【问题描述】:
假设我有两个这样的导航器:
export type RootStackParamList = {
Bootstrap: undefined;
Login: undefined;
MainApp: undefined;
};
export type MainTabsParamList = {
Explore: undefined;
Profile: undefined;
};
const MainTabs = createBottomTabNavigator<MainTabsParamList>();
const MainApp = () => (
<MainTabs.Navigator >
<MainTabs.Screen
name="Explore"
component={Explore}
/>
<MainTabs.Screen
name="Profile"
component={Profile}
/>
</MainTabs.Navigator>
);
const RootStack = createStackNavigator<RootStackParamList>();
const App = () => {
return (
<NavigationContainer>
<RootStack.Navigator initialRouteName="Bootstrap" headerMode="none">
<RootStack.Screen name="Bootstrap" component={Bootstrap} />
<RootStack.Screen name="Login" component={Login} />
<RootStack.Screen name="MainApp" component={MainApp} />
</RootStack.Navigator>
</NavigationContainer>
);
};
现在,如果我想从 Bootstrap 屏幕导航到 Profile 屏幕。我必须写:(正确注释的导航道具)
navigation.navigate('MainApp', {screen: 'Profile'})
但是打字稿在这里给出错误。说Type '{ screen: string; }' is not assignable to type 'undefined'。这是因为 typescript 不知道 MainApp 有子屏幕。所以我必须以某种方式编写ParamLists,以便打字稿了解子屏幕。我怎么做? react-navigation v5 支持吗?
【问题讨论】:
标签: typescript react-native react-navigation