i want to redirect to page "/items" if isAdmin true.
below is my code,
function Child() {
const isAdmin = getUser();
return isAdmin ? (
<Confirm />
) : (
<NotFound />
);
}
As seen in above code, if isAdmin true then i render confirm and if isAdmin false i am rendering NotFound.
But this will render NotFound within Parent component.
Instead i want to redirect to NotFound. How can I do it? Could someone help me with this. Thanks.
EDIT: what i have tried?
return isAdmin ? (
<Confirm />
) : (
<Route component={NotFound} />
);
But this still renders in same page.
i have used the same code in main component like below,
function Main() {
return (
<Switch>
<Route
exact
path="/home"
render={routeProps => (
<Layout>
<Home {...routeProps} />
</Layout>
)}
/>
//other routes here
<Route component={NotFound}/> //if none of the urls match then //renders notfound
</Switch>
);
}
how do i use something similar. thanks.