“UserOutematch” Código de respuesta

React Router DOM Corriente de ruta gancho

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

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código