“useroutEmatch” Réponses codées

REACT ROUTER DOM COURANT COURANT

import { useLocation } from 'react-router-dom'

// Location is, for example: http://localhost:3000/users/new

// Care! MyComponent must be inside Router to work
const MyComponent = () => {
	const location = useLocation()
    
    // location.pathname is '/users/new'
    return <span>Path is: {location.pathname}</span>
}

export default MyComponent
Mr Dom

useroutEmatch

// React Router v5:
// hook without argument returns match obj of current <Route>
// or takes obj argument identical to 'props' argument of matchPath
import { useRouteMatch } from 'react-router-dom'

function BlogPost() {
 let match = useRouteMatch({ 
   '/blog/:slug', 
   strict: true, 
   sensitive: true 
 })
 // Do something with the match...
 return <div />
}
Coffee Addict

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code