如果在安装组件后获得了元标记所需的数据,反应头盔会工作吗?

时间:2018-08-02 04:37:57

标签: reactjs meta-tags prerender react-helmet

import { Helmet } from "react-helmet";

    class Article extends Component {
        state = {
            articleContent: null,
        };
       componentDidMount() {
            this._getArticleDetail();
    }

        _getArticleDetail() {
            SingleArticle.getSingleArticle(this.props.match.params.id)
                .then(response => {
                    this.setState({
                        articleContent: response.data.article[0].content,
                    });
        }

    render() {
      let pageUrl = window.location.href;
      let prerenderHeader = "Location:" + pageUrl;
      return(
         <Helmet>
           <title>{this.state.articleContent && this.state.articleContent.title}</title>
           <meta name="description" content={this.state.articleContent && this.state.articleContent.description} />
           <meta name="keywords" content=this.state.articleContent && this.state.articleContent.keywords/>
         </Helmet>
)
}

我的问题是,当安装组件时,文章标题,描述为null。只有在异步api调用之后,我才能获取所需的信息。在这种情况下,元标记会更新吗?

0 个答案:

没有答案