【发布时间】:2021-06-27 01:45:24
【问题描述】:
我正在尝试定义 react-navigation 的类型(导航和路由道具),以便更容易自动完成 VS Code。
App(Stack) > Main(BottomTab)> [Home(Stack){Post}, Profile(Stack){UserProfile}] 在这种嵌套导航状态下,我想从 Post(Home) 导航到 UserProfile(Profile)。
这是我的 Stack 和 BottomTab 参数列表。
/* App Navigation Types */
export type AppStackParamList = {
Landing: undefined;
Main: undefined;
};
/* Main Navigation Types */
export type MainTabParamList = {
Home: undefined;
Crypto: undefined;
Posting: undefined;
Chat: undefined;
Profile: undefined;
};
/* Home Navigation Type */
export type HomeStackParamList = {
Post: { id: string } | undefined;
CategoryFilter: undefined;
Feed: undefined;
Search: undefined;
SetLocation: undefined;
};
/* Profile Navigation Type */
export type ProfileStackParamList = {
EditProfile: undefined;
MyPage: undefined;
UserProfile: { id: string } | undefined;
};
这些是每个屏幕的导航道具类型
export type PostNavProp = CompositeNavigationProp<
StackNavigationProp<HomeStackParamList, 'Post'>,
BottomTabNavigationProp<MainTabParamList>
>;
export type UserProfileNavProp = CompositeNavigationProp<
StackNavigationProp<ProfileStackParamList, 'UserProfile'>,
BottomTabNavigationProp<MainTabParamList>
>;
使用这种类型定义,navigation.navigate('Profile') 可以工作。但配置文件的初始屏幕路径不是“用户配置文件”。
当我尝试使用导航()函数的第二个参数(如navigation.navigate('Profile', {screen:'UserProfile'}))访问 UserProfile 时,它显示错误..
only 1st parameter works error message
我可以就这个问题获得一些建议吗?我需要立即帮助..拜托..
【问题讨论】:
标签: typescript react-navigation-v5