First, I've tried fixing this issue using this: Multiple params with React Router. But there's def. things I do not get in this context. I'm fairly new to react-router-dom
and I'm trying to have two params in the URL, like this: /:type/:projectid
.
I have instantiated my <Link>
like this, coming from an array of data:
let projectRoutePlaceholder = `${ele.type}/project${this.props.index}`
return(
<Router>
<Link to={projectRoutePlaceholder}>
....
</Link>
</Router>
);
When I hover on my content, I therefore have the route URL displaying on the bottom left of the browser. On my index.js
file, I've set up my routes like this:
ReactDOM.render(
<React.StrictMode>
<Router>
<Route exact path='/' component={App} />
<Route exact path='/index' component={ProjectIndex} />
<Route exact path='/info' component={Info} />
<Route exact path='/:type/:id' component={ProjectTemplate} />
</Router>
</React.StrictMode>,
document.getElementById('root')
Now, two issues I'm not able to fix.
- When I click on a
<Link>
element, it does not send me to theProjectTemplate
component and it stays on the<Link>
element. When I force (refresh the page with the exact route, e.g:commercial/project0
), it works. - When I click once again on the
<Link>
element, params gets concatenated (e.g:commercial/commercial/project0
)
How can I fix these two issues?