Coding⏱️ 2 min read📅 2026-06-03
How to Fix: Error: [PrivateRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
Error in React Router v6 private route component.
Quick Answer: The issue is caused by the Navigate component being used directly as a child of Route. Instead, use a Fragment or wrap the Navigate component with a Route.
To resolve the error "Error: [PrivateRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>", you need to wrap your PrivateRoute with a Route component.
🛠️ Step-by-Step Verified Fixes
Method 1: Wrap PrivateRoute with Route component
- Step 1: Import the Route component from react-router-dom.
Method 1: Wrap PrivateRoute with Route component (continued)
- Step 2: Wrap your PrivateRoute component with the Route component.
Here is an example of how you can do it:
import React from 'react';
import { Route, Navigate } from 'react-router-dom';
import { isAuth } from 'auth';
function PrivateRoute({ element, path }) {
const authed = isAuth();
const ele = authed === true ? element : ❓ Frequently Asked Questions
Step 1: Import the Route component from react-router-dom. Step 2: Wrap your PrivateRoute component with the Route component. 🛠️ Related Fixes
How to Fix: Stuck in tutorial hell after 4 years: How do I b
Fix Stuck in tutorial hell after 4 years: How do I bui. Practice build
How to Fix: Trying to sync mutliple audio tracks to a movie
Fix Trying to sync mutliple audio tracks to a movie bu. Consider using
How to Fix: Failed to merge latest branches from upstream re
Fix Failed to merge latest branches from upstream repo. Try running 'g