I have an app layout like this:
function App() {
return (
<Router>
<Header />
<main className="py-1">
<Route path="/admin" component={Admin} />
<Container>
<Switch>
<Route path="/" component={HomeScreen} exact />
<Route path="/login" component={LoginScreen} exact />
<Route path="/sitemap" component={SiteMap} exact />
{/* SOME MORE ROUTES LIKE THESE .... */}
<Route path="*">
<Error404 />
</Route>
</Switch>
</Container>
</main>
<Footer />
</Router>
);
}
export default App;
I am setting an Admin Page and I don't want to put it into Container for some reason like I want to set a sidebar just for the admin page if I put this into the container then it becomes ugly not look like a side bar and I don't want to change the layout of the container as well it's working well for the other components. But if I put the Admin component outside the container then <Switch>
thinks it's not a valid URL and the Both Admin
+ <Error404 />
components loads Simultaneously.
So I want to put some logic here that the Route:
<Route path="*"><Error404 /></Route>
should ignore the URL starting with /admin and which is not wrapped in the <Switch>
tag and not hit with the Error404
Is that possible? Is there any other approach to do the same?