The footer must display a different CTA depending on if the user is on the Home page, or on the Product page. The product page is a single page that renders product information of the item selected on the home pages, and the way I have accomplished that is by using useParams(), and creating the a correlation between the page.id (comes from the data file ) and pageID.
I thought I could do the same thing for the footer, but I am getting an error claiming that everything is undefined, literally, everything. This is my footer component. As you can see, I am importing the data for the footer from the data folder as "pageItems":
import React from 'react';
import { useParams } from 'react-router';
import pageItems from '../../data/footerData';
function Footer() {
const { pageID } = useParams();
const individualPage = pageItems.find(page => page.id === pageID);
return (
<div className="footer-container">
<p>{individualPage.copy}</p>
<a href="https://www.lego.com/kids" target="_blank">
<img src={individualPage.cta} alt="cta" />
</a>
</div>
);
}
The data file (which is just a javascript file) is structured in the following way:
const footerData = [
{
id: '1',
copy: 'You can find more fun at',
cta: HomeCta,
href: 'https://www.something.com',
},
];
I am sure I could create the correlation between <Route path="/:videoID"> (which works), and the footer, but I can't seem to get it right.
Edit: This is how my routing page is set up at the moment:
return (
<Router>
<Navbar />
<Switch>
<Route path="/:videoID">
<FeaturedVideo />
</Route>
<Route exact path="/">
<Home />
</Route>
</Switch>
<Footer />
</Router>
);
}
Any help will really help. thank you so much in advance!
And as a side note, I am using the react version that uses react hooks