【发布时间】:2020-12-10 10:24:22
【问题描述】:
我创建了一个 <Authorise /> 组件,它根据布尔“允许”属性呈现“是”或“否”属性。
export const Authorise = ({
allow = false,
yes = () => null,
no = () => null
}) => (allow ? yes() : no());
<Authorise /> 组件按预期工作,但是当我尝试渲染 <Route /> 时,只渲染第一个路由,而忽略其余的 <Route /> 组件。
为什么会这样?如果我在<Authorise /> 组件之外渲染路由,它可以正常工作。只有当通过<Authorise /> 组件渲染组件时它才不起作用,我不知道为什么。
查看我的示例以查看问题: CodeSandbox
【问题讨论】: