1

好人,你好!

我在使用 Relay 时遇到了一些问题。由于某种原因,没有数据传递给我的侧边栏组件。数据在我的<script id="preloadedData">节点中可用,但它没有被传递到它应该去的地方

客户端.js

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

路线.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

我不知道出了什么问题,我需要你的帮助,拜托!

4

1 回答 1

0

问题是不正确的中继查询使用和同构中继路由器中的错误的组合:链接到问题

于 2016-09-30T07:56:20.793 回答