How to match pattern with Id on them react router

I am new to react. I have a route with react router that takes :id as parameter, how do I match this using react-router-dom useLocation.

basically path can be posts or post/21
how do I match post/21 to render a component, I want to render a seperate component if I
am on the detail page

{path === 'post/:id' ? <PostDetail /> : <Posts /> }

but use location returns posts/1 which I can’t use to match the post detail

summary
Any path that matches: post/:id