在 Relay 中,如何将路由参数传递给组件?
我有这条路线:
import Relay from 'react-relay'
export default class ConversationRoute extends Relay.Route {
static queries = {
account: (Component) => Relay.QL`
query root {
account {
${Component.getFragment('account')}
}
}
`
}
static paramDefinitions = {
conversationId: {required: true}
}
static routeName = 'ConversationRoute'
}
而这个组件:
class CommentListApp extends React.Component {
render() {
let account = this.props.account
if (!account) return <div />
return <CommentList comments={account.conversation.comments} />
}
}
export default Relay.createContainer(CommentListApp, {
initialVariables: {
conversationId: null
},
fragments: {
account: () => Relay.QL`
fragment on Account {
conversation(id: $conversationId) @include(if: $conversationId) {
comments {
${CommentList.getFragment('comments')}
}
}
}
`
}
})
但这不起作用。该conversationId
参数不会传递到组件中。
我错过了什么?