I am creating an admin app where i want make a protected route for admin dashboard. Signin and Signup routes are public. Before creating a protected route every route was working well. I created a higher order component to create a private route. I replaced the route as Private route and the page loads and terminal gives no error. But the page renders nothing and console throws error as private route is not a route component. All children of routes must be route or react.fragment.
Here is my app.tsx file
import React from 'react';
import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router-dom';
import {Home, Signup, Signin} from './container/index';
import './App.css';
import PrivateRoute from './components/common/HOC/Index';
function App() {
return (
<div className="App">
<Router>
<Routes>
<PrivateRoute path="/" element={<Home/>} />
<Route path="/signup" element={<Signup />} />
<Route path="/signin" element={<Signin />} />
</Routes>
</Router>
</div>
);
}
export default App;
Here is my private router component.
import React from 'react';
import { Route } from 'react-router-dom';
const PrivateRoute = (props:any) => {
return <Route {...props}/>
}
export default PrivateRoute;