useParams react class components code example
Example 1: useparams
import {
BrowserRouter as Router,
Switch,
Route,
useParams
} from "react-router-dom";
function BlogPost() {
let { slug } = useParams();
return <div>Now showing post {slug}</div>;
}
ReactDOM.render(
<Router>
<Switch>
<Route exact path="/">
<HomePage />
</Route>
<Route path="/blog/:slug">
<BlogPost />
</Route>
</Switch>
</Router>,
node
);
Example 2: useparams
import { useParams } from "@reach/router"
const User = () => {
const params = useParams();
return <h1>{params.userName}</h1>
)