close

[Fixed] Error: [PrivateRoute] is not a component. All component children of must be a or

Today We are Going To Solve Error: [PrivateRoute] is not a component. All component children of must be a or in reactjs. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix Error: [PrivateRoute] is not a component. All component children of must be a or Error?

  1. How to Fix Error: [PrivateRoute] is not a component. All component children of must be a or Error?

    To Fix Error: [PrivateRoute] is not a component. All component children of must be a or Error just set your router component. First of all, set your router component to element prop by using this command. It will simply remove your error. So try this:
    <Routes> <Route exact path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/dashboard" element={<Dashboard />} /> </Routes>

  2. Error: [PrivateRoute] is not a component. All component children of must be a or

    To Fix Error: [PrivateRoute] is not a component. All component children of must be a or Error just Run this command. You can try this code to solve your error.
    {auth && ( privateRoutes.map(route => <Route path={route.path} key={route.path} element={auth.isAuthenticated ? <route.component /> : <Navigate to={ROUTE_WELCOME_PAGE} replace />} /> ) )} I hope this will help you!

Solution 1 : set your router component

First of all, set your router component to element prop by using this command. It will simply remove your error. So try this:

<Routes>
  <Route exact path="/" element={<Home />} />
  <Route path="/about" element={<About />} />
  <Route path="/dashboard" element={<Dashboard />} />
</Routes>

Solution 2 : Run this command

You can try this code to solve your error.

{auth && (
  privateRoutes.map(route =>
    <Route
      path={route.path}
      key={route.path}
      element={auth.isAuthenticated ? <route.component /> : <Navigate to={ROUTE_WELCOME_PAGE} replace />}
    />
  )
)}

I hope this will help you!

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

Leave a Comment