📌  相关文章
📜  反应路由器 dom 当前路径挂钩 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:04.378000             🧑  作者: Mango

代码示例1
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 Path is: {location.pathname}
}

export default MyComponent