2016-09-27 55 views
1

好人,你好!同構中繼路由器:無法將數據傳遞到組件

我有一些打嗝讓我的頭與周圍的工作。由於某種原因,沒有數據傳遞給我的邊欄組件。該數據是在我<script id="preloadedData">節點可用,但它沒有獲得通過到它應該去

client.js

match({ routes, history: browserHistory }, (error, redirectLocation, renderProps) => { 
    if (error) throw error; 
    IsomorphicRouter.prepareInitialRender(environment, renderProps).then((props) => { 
     ReactDOM.render(
     <Router {...props} />, 
     root 
     ); 
    }); 
}); 

routes.js

[{ 
    path: '/', 
    component: App, 
    indexRoute: { 
     getComponents: (nextState, cb) => { 
     Promise.all([ 
      System.import('./Home/Hero'), 
      System.import('./Home'), 
      System.import('../components/Sidebar') 
     ]) 
      .then(modules => cb(null, { 
      hero: modules[0].default, 
      content: modules[1].default, 
      sidebar: modules[2].default 
      })) 
      .catch((e) => { throw e; }); 
     }, 
     queries: { 
      sidebar: { 
       joke:() => Relay.QL`query Joke { randomJoke }`, 
       quote:() => Relay.QL`query Quote { randomQuote }` 
      } 
     } 
    } 
}]; 

App.js - 普通無狀態組件(無中繼包裝)

<div className={s.root}> 
    {hero} 
    <main> 
    <Header /> 
    {content} 
    {sidebar} 
    </main> 
    <Footer /> 
</div> 

Sidebar.js

... 

Relay.createContainer(Sidebar, { 
fragments: { 
    joke:() => Relay.QL` 
    fragment on Joke { 
     text 
    } 
    `, 
    quote:() => Relay.QL` 
    fragment on Quote { 
     text, 
     author, 
     sourceUrl 
    } 
    ` 
} 
}); 

邊欄道具:

{"history":{},"location":{"pathname":"/","search":"","hash":"","state":null,"action":"POP","key":"aelohd","query":{},"$searchBase":{"search":"","searchBase":""}},"params":{},"route":{"queries":{"sidebar":{}}},"routeParams":{},"routes":[{"path":"/","indexRoute":{"queries":{"sidebar":{}}},"childRoutes":[{"path":"/register","queries":{"content":{}}},{"path":"/publications","queries":{"content":{}}}]},{"queries":{"sidebar":{}}}],"children":null,"relay":{"pendingVariables":null,"route":{"name":"_aggregated___route_1_sidebar_joke___route_1_sidebar_quote","queries":{},"params":{}},"variables":{}}} 

此外,是顯示以下錯誤:RelayContainer: Expected prop 'joke' to be supplied to 'Sidebar', but got 'undefined'. Pass an explicit 'null' if this is intentional.(同樣爲quote

我沒有知道什麼是錯的,我會的需要你的幫助,請!

回答

相關問題