I am using react-router-dom and according to docs it says for url pattern https:\\example.com\user\:id\:gender
we can use useParams() hook to read the patters like
import {useParams, Route} from react-router;
<Route exact path="/user/:id/:gender" component={User}/>
const user=(props)=>{
const params = useParams()
}
//params = {id:'1',gender:'f'}; output for url pattern >>> https:\\example.com\user\1\f
But in my case, I have two requirement
- gender field is sometime required and some time not, then what changes needed in the Router?
- How to read url pattern
https://example.com/user?id=1&gender=f, because in this patter If I interchange the order then no effect will be on parameter object.