I am wanting to create a dynamic route in my react app using react-router-dom. I have been reading documents over it but none of it is really making sense in my situation. I have a projects page, and then you can click on a link in the projects page and it takes you to a new page called project details. the url is different in each one.
App.js
<BrowserRouter>
<Switch>
<Route path="/" component={Home} exact />
<Route path="/about" component={About} exact />
<Route path="/projects" component={Projects} exact />
<Route path="/workshops" component={Workshops} exact />
<Route path="/bodywork" component={Bodywork} exact />
<Route path="/contact" component={Contact} exact />
<Route path="/:projectdetails" component={ProjectDetails} exact />
</Switch>
</BrowserRouter>
there are ten different projects with all different names. they are in a data file like this:
export const ObjOne = {
title: 'Feldbewegung',
img: './images/bodyOfEarth.jpg',
alt: 'Feldbewegung',
link: '/feldbewegung-details'
};
export const ObjTwo = {
title: 'Nonmaterial city beautification',
img: './images/bodyOfEarth.jpg',
alt: 'Nonmaterial city beautification',
link: '/nonmaterial-city-beautification-details'
};
export const ObjThree= {
title: 'Body of Earth',
img: './images/bodyOfEarth.jpg',
alt: 'Body of Earth',
link: '/body-of-earth-details'
};
there is three for example. and they get passed into Projects.js
import { ObjOne, ObjTwo, ObjThree, ObjFour, ObjFive, ObjSix, ObjSeven, ObjEight, ObjNine, ObjTen} from '../components/Data/projectsData';
function ProjectImage({img, alt, link, title}) {
return (
<>
<div className="ProjectImage">
<img className="project-img" src={img} alt={alt} />
<a className="project-link" href={link}>{title}</a>
</div>
</>
)
}
function Projects({}) {
return (
<>
<Navbar1 />
<div className="page">
<Container className="projects-container">
<ProjectImage {...ObjOne} />
<ProjectImage {...ObjTwo} />
<ProjectImage {...ObjThree} />
...continuing to ObjTen..
is there a way to add dynamic routes or pages somehow?