簡體   English   中英

React-Native導航到新屏幕不起作用

[英]React-Native navigation to new screen not working

我正在嘗試建立一個onPress按鈕,該按鈕將顯示一個跟蹤屏幕。 我可以看到控制台日志,其中顯示了其輸入的代碼,但沒有導航到該屏幕。 抽屜鏈接上的同一屏幕導航到我想要的屏幕

import { TabNavigator, StackNavigator, navigationOptions, NavigationActions } from "react-navigation";

trackButton(){return(

      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            <Button
              title="Start Tracking"
              onPress={() => {
                console.log('Testing');
                /* 1. Navigate to the Details route with params */
                const resetAction = NavigationActions.reset({
                  index: 0,
                  actions: [
                    NavigationActions.navigate({ routeName: 'TrackingScreen'})
                  ]
                })
                this.props.navigation.dispatch(resetAction)
              }}
            />
          </View>
        );

reset不再屬於實現的NavigationActions 隨着V2的發布, reset和許多其他操作的實現被移交給StackActions 所以你應該使用StackActions.reset({...})請參閱

您的代碼應如下所示:

onPress={() => {
   console.log('Testing');
   /* 1. Navigate to the Details route with params */
   const resetAction = StackActions.reset({
   index: 0,
   actions: [
      NavigationActions.navigate({ routeName: 'TrackingScreen'})
   ]
   })
   this.props.navigation.dispatch(resetAction)
}}

希望這可以幫助。 快樂編碼:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM