如何从组件返回Route?

问题描述 投票:0回答:1
export const RbacRoute = ({ element: OriginalComponent, path, routeName }) => {
  let { userRole, permitedRoutes } = useContext(UserContext());
  return <Route path={path} element={<OriginalComponent />} />;
};
Uncaught Error: \[RbacRoute\] is not a \<Route\> component. All component children of \<Routes\> must be a \<Route\> or \<React.Fragment\>

Uncaught Error: \[RbacRoute\] is not a \<Route\> component. All component children of \<Routes\> must be a \<Route\> or \<React.Fragment\>
reactjs
1个回答
0
投票

您似乎想在检查用户权限的同时创建受保护的路由。

您不能使用另一个组件作为

Routes
的子组件。

要应用受保护的路由,您可以按照此操作answer

© www.soinside.com 2019 - 2024. All rights reserved.