从另一个屏幕导航后如何重新加载页面

Abh*_*rav 5 javascript reactjs react-native react-redux

// 我正在使用以下代码将一个屏幕导航到另一个屏幕,即主页。但是当我浏览主页时,我必须刷新页面 ..reload 。目前,当我来到主屏幕时,生命周期方法没有被调用。特别是 UserAvatar 组件,我必须刷新或回忆。请建议

    <View style={{textTransform: 'lowercase'}}><YellowBtn label="Go to 
  Dashboard"
               OnClick={this._redirectCustomerView}/></View>


        _redirectCustomerView = () => {
            this.props.navigation.navigate('UserHome');
          };
Run Code Online (Sandbox Code Playgroud)

// 下面是首页

 export default class App extends React.Component {
      constructor(props) {
        super(props);
        this.state = { title: 'Hello!', hasFooterPermission: false };
        console.log("Valuueeeeeee");
      }

      async componentDidMount() {
        const homeFooter = await hasPermission('clm.360D.fe.restrictedView.allowed');

        this.setState({
          hasFooterPermission: homeFooter
        })
      }

      onSearchClick = () => {
        this.props.navigation.navigate('SubscriberSearch');
      };
      componentWillMount(){
        console.log(" Home page dataaaa");
      }


      render() {
        return (
          <View>
            <ImageBackground source={BG} style={{ width: '100%', height: '100%' }} resizeMode="cover">
              <View  style={{ paddingTop: 5 , alignContent:'space-between',flexDirection:'row'}}>
                <View style={{alignSelf: 'flex-start', flex:1}}>
                  <UserAvatar navigationProps={this.props.navigation} avatarSize={40} isTouchable={true}/>
                </View>
                {/* <View style={{alignSelf: 'flex-end'}}>
                  <Icon
                    name="bell-outline"
                    type="MaterialCommunityIcons"
                    style={{ color: '#FFFFFF' }}
                    onPress={() => Toastr.showToast('No new notifications!', 3000)}
                  />
                </View> */}
              </View>
Run Code Online (Sandbox Code Playgroud)

Sha*_*van 11

使用推送而不是导航

this.props.navigation.push('UserHome');
Run Code Online (Sandbox Code Playgroud)


pin*_*ric 0

主页没有义务知道是否需要刷新页面。建议的方法是,当满足重新加载的条件(头像更新、用户属性更改等)时,调用实体应转到主页,并在需要时请求重新加载(即,window.location.reload(true)