This can be done by using history api of JS. history.pushState()
this history api provide us a pushState method which can take a data, title and a url where it should redirect. this is used by react-router-dom behind the scene too