How do you create nested routes?
Short answer: To create nested routes, place a <Route /> inside another route's component.
Explain a bit more
Example: import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom'; function App() { return ( <Router> <div> <nav> <Link to="/about/team">Team</Link> <Link to="/about/company">Company</Link> </nav> <Switch> <Route exact path="/about" component={About} /> <Route path="/about/team" component={Team} /> <Route path="/about/company" component={Company} /> </Switch> </div> </Router> ); } function About() { return <h2>About Page</h2>;
Example code
} function Team() { return <h3>Team Page</h3>;
} function Company() { return <h3>Company Page</h3>;
}
Real-world example (ShopNest)
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png