组件的构造函数第二次不工作

Constructor of Component is not working for the second time

我有一个组件 class:

class AutoPage extends Component {
constructor(props) {
    super(props);
    console.log("Auto is " + this.props.route.params.auto);
    this.state = {
        avto: this.props.route.params.auto,
    }
    this.array = [
        this.state.avto.PICTURE,
    ];

    for (let dopImage of this.state.avto.DOP_FOTO.VALUE) {
        this.array.push(dopImage);
        //console.log(avto);
    }
    }
}

我正在从另一个地方打开这个组件:

<TouchableOpacity onPress={() => navigate('AutoPage', {
                auto: item
              })}>

这是我的抽屉导航:

 <Drawer.Navigator drawerContent={props => <CustomSidebarMenu {...props} />} width={Dimensions.get('window').width - 130}
  component={CustomSidebarMenu}>
  <Stack.Screen name="AutoListPage" component={AvtoListPageNav} />
  <Stack.Screen name="AutoPage" component={AutoPage} options={{ headerTitle: "GorodAvtoPrime", headerTitleAlign: "center" }} /> 
</Drawer.Navigator>

当我单击 TouchableOpacity 时,AutoPage 打开并且其构造函数工作。但是当返回并再次单击 TouchableOpacity 时,AutoPage 打开并且其构造函数不起作用。我正在 this.props.route.params.auto 中获取以前的数据。每次单击 TouchableOpacity 时,如何使 AutoPage 的 运行 构造函数?

您可能想要订阅 focus 导航事件。屏幕正在重复使用,因此不会再次创建。

https://reactnavigation.org/docs/navigation-events

class AutoPage extends Component {
  constructor(props) {
    super(props);
    this.state = {
        avto: null,
    }
  }

  componentDidMount() {
    this._unsubscribe = this.props.navigation.addListener('focus', () => {
      // Update your state here
    });
  }

  componentWillUnmount() {
    this._unsubscribe();
  }
}