1 import { createStackNavigator,StackNavigationProp } from '@react-navigation/stack'; 

为了对路由名和参数进行类型检查,首先要创建带有路由名到其参数的映射的对象类型

index.js

1 export type stackParamsList={
2 BottomTab:{ 3 screen?:string 4 }; 5 Detail:{ 6 id:number 7 }; 8 }

 1 export type navigationProp=StackNavigationProp<stackParamsList> 导出

这将为NavigatorScreen组件提供类型检查和intelliSense。

 1 const Stack=createStackNavigator<stackParamsList>() 

注释 navigation prop

1 import  { navigationProp } from '@/navigator/index'
2 interface Iprops{
3     navigation:navigationProp
4 }

注释route prop

1 import { RouteProp } from '@react-navigation/native';
2 import {stackParamsList} from '@/navigator/index'
3 type  routeProp=RouteProp<stackParamsList,'Detail'>
4 interface Iprops{
5     route:routeProp
6 }

 

相关文章:

  • 2021-08-10
  • 2021-12-27
  • 2022-12-23
  • 2021-05-09
  • 2021-12-13
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-12
  • 2021-08-12
  • 2021-08-07
  • 2021-10-08
  • 2021-07-24
  • 2021-12-04
相关资源
相似解决方案