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.
Contents
How to Fix Error: [PrivateRoute] is not a component. All component children of must be a or Error?
- 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>
- 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
- bash: pip: command not found
- yntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response
- Uncaught (in promise) DOMException: play() failed because the user didn’t interact with the document first
- javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)