I'm using React and I need to navigate the user to a profile page, i.e. mydomain.com/profile/myusername but I'm not sure how to extract the 'myusername' from the url? Snippet of my code are below, please help!
Many thanks
Routing
class App extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route path="/" component={Main} exact />
<Route path="/profile" component={Profile} exact />
</div>
</BrowserRouter>
);
}
}
export default App;
My hyperlink
<Link to={`profile/${obj.username}`}>{obj.username}</Link>
My profile page
import React, { Component } from 'react';
class Profile extends Component {
componentDidMount() {
}
render() {
return (
<div>
<h1>myusername</h1>
</div>
);
}
}
export default Profile;