将连接的组件传递到React Route导致错误

时间:2017-08-15 05:04:16

标签: reactjs redux react-redux

当我将连接的组件export default connect(ComponentName)传递到React Route route时,如下面的代码,

<Route path={path} component={ComponentName}/>

我收到以下错误,

You must pass a component to the function returned by connect. 
Instead received {"match":{"path":"/:code","url":"/sample-
code","isExact":true,"params":{"code":"sample-code"}},"location":
{"pathname":"/sample-code","search":"","hash":""},"history":
{"length":40,"action":"POP","location":{"pathname":"/sample-
code","search":"","hash":""}}}

我可以将连接的组件传递给route组件吗?

1 个答案:

答案 0 :(得分:4)

connectmapStateToProps等函数作为其参数。你可能意味着connect()(ComponentName)

您绝对可以将连接的组件传递到具有component道具的路线,而无需使用render道具。