同构中继路由器:无法将数据传递给组件
isomorphic-relay-router: unable to pass data to component
好人,你好!
我在使用 Relay 时遇到了一些问题。由于某种原因,没有数据传递到我的 Sidebar 组件。数据在我的 <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
相同)
我不知道出了什么问题,我需要你的帮助!
问题是不正确的中继查询使用和同构中继路由器中的错误的组合:link to the issue
好人,你好!
我在使用 Relay 时遇到了一些问题。由于某种原因,没有数据传递到我的 Sidebar 组件。数据在我的 <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
相同)
我不知道出了什么问题,我需要你的帮助!
问题是不正确的中继查询使用和同构中继路由器中的错误的组合:link to the issue