如何使用反应导航?

时间:2019-08-05 08:15:24

标签: javascript typescript react-native

我有一个打字稿代码。当我按下交通按钮时,导航不起作用。如何使用反应导航?

在同一目录中,我有带有index.tsx文件的'Transportations'文件夹。在索引文件中,默认情况下,我导出了一些View的

<Content padder>
    <HomeItem
      onPress={() => navigation.navigate("Transportations")}
      icon="repeat"
      title={t("routes_transportations")}
    />
    <HomeItem
      onPress={() => navigation.navigate("Vaccination")}
      icon="medkit"
      title={t("routes_vacination")}
    />
    <HomeItem
      onPress={() => navigation.navigate("Sampling")}
      icon="color-filter"
      title={t("routes_sampling")}
    />
</Content>

什么都不会发生

1 个答案:

答案 0 :(得分:1)

如果您的屏幕位于堆栈导航器或其他react-navigation堆栈中,则应在组件中访问类似//import //component decorator export class CoordonneesComponent implements OnInit, OnDestroy { private coachProfile; token: string = localStorage.getItem('token'); us_id : string; us_lang: string; infos_profile: any; online: any; constructor(private translate: TranslateService,private coachService: CoachService, private router: Router) { } ngOnInit() { this.coachProfile=this.coachService.coachProfile(this.token) .subscribe((data) => { this.infos_profile = data.results; this.online = this.infos_profile.online_profile; this.translate.use(this.infos_profile.us_lang) this.infos_profile.lang= this.infos_profile.us_lang; }); ..... } updateCoordonees() { this.coachService.updateProfile(this.infos_profile, this.token, this.us_id) .subscribe((data: any) => { if(data.success && data.msg!=null) { // do something } else { // do something } }, (err) => { // do something }); } ngOnDestroy() { this.countrieList.unsubscribe(); this.coachProfile.unsubscribe(); } } 的导航