I'm trying to add exact keyword to my private router but it is not rendering the component. It works when it's a normal route. Here is my auth code:
<AuthProvider>
<Router>
<div>
<Header />
<Switch>
<Route exact path="/login" component={Login} />
<PrivateRoute path="/" component={Home}/>
</Switch>
</div>
</Router>
</AuthProvider>
Based on firebase auth state change. I pass the currentUser using auth context provider:
<AuthContext.Provider
value={{
currentUser
}}
>
{children}
</AuthContext.Provider>
code for private route:
const PrivateRoute = ({ component: RouteComponent, ...rest}) => {
const { currentUser } = useContext(AuthContext);
return (
<Route
{...rest}
render={(routeProps) =>
!!currentUser ? (
<RouteComponent {...routeProps}/>
)
: (
<Redirect to={"/login"} />
)
}
/>
);
};
What is the issue here?