user

Mohamed Atef

6 Aug 2022

React.Fragment. React.Fragment can only have key props and children

React js

Hello everyone I am getting this error in my Reactjs application

React.Fragment. React.Fragment can only have key props and children

My code is 

export const renderRoutes = (routes = []) => (
 <Suspense fallback={<LoadingScreen />}>
 <Switch>
 {routes.map((route, i) => {
 const Guard = route.guard || Fragment;
 const Layout = route.layout || Fragment;
 const Component = route.component;

 return (
 <Route
 key={i}
 path={route.path}
 exact={route.exact}
 render={(props) => (
 <Guard DeepLink={props.pathname}>
 <Layout>
 {route.routes
 ? renderRoutes(route.routes)
 : <Component {...props} />}
 </Layout>
 </Guard>
 )}
 />
 );
 })}
 </Switch>
 </Suspense>
);

const routes = [
 {
 exact: true,
 guard: GuestGuard,
 path: '/404',
 component: lazy(() => import('src/views/errors/NotFoundView'))
 },
]

How can I solve this issue?

Comments

Jo Micheal

6 Aug 2022

Best Answer

best answer

Fragment cannot have any props the only way to pass to the Fragment is the children (Components). 
If you removed the DeepLink prop it will work fine.

Replies

Mohamed Atef

6 Aug 2022

githubgithubgithub

Thank you, this was the problem.
I have to find another way to pass these data inside the Web Guard

© 2024 Copyrights reserved for web-brackets.com