在Route之外渲染组件

时间:2017-07-24 04:23:09

标签: reactjs

我有一个Public和Authenticated函数,我用它来控制使用react路由器v4的身份验证,并且已经向我指出我应该在React.createElement(component, { ...props, loggingIn, authenticated })的呈现之外创建这个<Route />组件。我不确定我应该怎么做或为什么这样做。请解释并显示?

const Public = ({ loggingIn, authenticated, component, ...rest }) => (
  <Route
    {...rest}
    render={(props) => {
      return !authenticated ?
      (React.createElement(component, { ...props, loggingIn, authenticated })) :
      (<Redirect to="/" />);
    }}
  />
);

1 个答案:

答案 0 :(得分:1)

这应该对你有用,因为你已经有一个组件要传递到ng以便在这里呈现。考虑到node.js cli是用户定义的元素,请将<Public />更改为component

这来自React文档User-Defined Components Must Be Capitalized

Component
相关问题