Cannot get url parameter link in mern

Hello all,

I cannot get specific link of the posts in the PostItem.js in client folder. I want to make if someone clicks on the title then it will goes to that particular post’s page with full description and title where only that posts information will be seen. I have implemented redux too which is getPost in postActions.js . the problem is here if someone clicks on title, the page does to the particular post’s page with the link but the content cannot be seen there which is coming from Post.js in client folder. please help me solve this issue.

the github repo

Routing is not done by <Link> component, but by <Route>, therefore having Link with component is wrong. So you need <Route component={Post} path={/post} />, but you can’t put it in PostItem because of this <Route exact path="/" component={PostItem} /> (when route is not exactly / PosItem gets unmounted, it’s gone).

Solution to fix navigation:

Change Link to be <Link to={/post/${_id}}> in PostItem.js
Add <Route path="/post" component={Post}/> in App.js

There are still bugs in your code, but we’ll leave them for the next post.

1 Like