2017-12-14 12 views
1

リア・プロジェクトで、アリ・デザインとサーバー・サイド・レンダリングを使用しています。 私のヘッダーはユーザーの認証ステータスに従って表示されます。ユーザーが認証されている場合、appHeaderが使用されます。フルページロードでページの更新時にリアクションが正しく表示されない

import React, { Component } from 'react' 
import { connect } from 'react-redux' 
import { Layout, BackTop, Button } from 'antd' 
import LandingHeader from './_Landing/Header/LandingHeader' 
import AppHeader from './Common/AppHeader' 
import { withRouter } from 'react-router-dom' 
import { bool, object } from 'prop-types' 

const { Content, Footer } = Layout; 

class AppLayout extends Component { 
    constructor (props) { 
    super(props) 
    this.state = {} 
    } 

    render() { 
    const { children, location } = this.props 

    const isLoggedIn = this.props.isAuthenticated 
    let AppHeaderConditional = null 
    if (isLoggedIn && location.pathname != '/' && location.pathname != '/login' && location.pathname != '/signup') { 
     AppHeaderConditional = <AppHeader /> 
    } else { 
     AppHeaderConditional = <LandingHeader /> 
    } 

    return (
     <div className='landing-page-wrapper' data-pathname={`${location.pathname}`}> 
     {AppHeaderConditional} 
     <Layout> 
      <Content> 
      {children} 
      </Content> 
     </Layout> 
     <BackTop> 
      <Button type='primary' shape='circle' icon='up-circle-o' size='large' /> 
     </BackTop> 
     <Footer className='footer' style={{ textAlign: 'center' }} > 
      © 2017 - 
     </Footer> 
     </div> 
    ) 
    } 
} 

AppLayout.propTypes = { 
    isAuthenticated: bool, 
    children: object, 
    location: object 
} 

const mapStateToProps = state => { 
    return { 
    isAuthenticated: state.user.isAuthenticated 
    } 
} 

export default withRouter(connect(mapStateToProps)(AppLayout)) 

(私はリンクして会員ページに自宅からのナビゲートを意味する)には、クラス名と正しいレンダリングが、ページの更新に、このクラスは、ヘッダに追加されません。コンソールログに「警告:サーバーHTMLに...が含まれているとは思われませんでした」というエラーが表示されます。

私はこのコンソールの警告について調査しましたが、何も助けになりませんでした。私は純粋な試みた:false(https://github.com/reactjs/react-redux/blob/master/docs/troubleshooting.md)、いくつかの他のものが、私は問題を解決することができません。あなたは、クライアント上でサーバーとbrowserRouter上staticRouterを使用する必要が

+0

誰がisAuthentifiedをコンポーネントに渡しますか?コードにclassNameが表示されません。より多くの情報を提供できますか?サーバーがユーザー認証済みかどうかわからないように見える –

+0

ブラウザのコンソール要素タブで、ヘッダーがクラス(appHeader)ではなく、Reactタブヘッダーにクラス「appHeader」がある –

+0

編集された質問に完全なコードが追加されました。 –

答えて

0

私は解決策を見つけました。必要なのは以下の通りです。何らかの理由でページがクライアント上で2度目のレンダリングをするため、私は理由はわかりませんが、これは解決策です。

componentDidMount() { 
    this.setState({ mounted: true }) 
} 
関連する問題