I'm currently working on a site that offers expeditions, and one of the pages is supposed to have nested routes inside it eg: /expeditions/antarcticasouthgeorgia
.
I've been following some of the other questions asked about this, and I can't seem to get my implementation to work.
My code and references are shown below. I appreciate the help. Thank you!
App.js
class App extends Component {
render() {
return (
<div className="App">
<Router>
<ScrollToTop/>
<NavMenu />
<Switch>
<Route exact path='/' component={Home}/>
<Route exact path="/expeditions" component={Expeditions}/>
<Route path="/expeditions/antarticasouthgeorgia" component={InnerExpeditions}/>
<Route path="/about" component={About}/>
<Route path="/contact" component={Contact}/>
</Switch>
</Router>
</div>
);
}
}
export default App;
Expeditions.js
class Expeditions extends Component {
render() {
const OverviewThumbs = (props) => {
return (
props.data.map((item, index) => {
return (
<Col sm={6} lg={4}>
<Link to={item.url} className={`overview_thumbs overview_thumbs-${index}`} style={{ backgroundImage: `url(${item.image})` }}>
<div className="overview_header">
{item.title}
</div>
</Link>
</Col>
)
})
)
}
const data = [
{
title: 'Antartica & South Georgia',
image: contentImg1,
url: '/antarticasouthgeorgia'
},
]
return (
<div className="page-fade-in expeditions rootPadding">
<Container fluid className="content overview px-0 pb-0" >
<Row className="g-0">
<Router basename="/expeditions">
<OverviewThumbs data={data} />
</Router>
</Row>
</Container>
</div>
);
}
}
export default Expeditions;
References
React how to create sub pages with react router to display?