useHistory, useLocation, useParams

roglog·2021년 2월 18일
1

useHistory


  • history에 접근할 수 있게 해줌
    *history
  • Ex)
  import {useHistory} from "react-router-dom"

  const history = useHistory();
  history.push("/home");

useLocatoin


  • location object를 return함 (현재 url을 보여줌)
    *location
  • Ex)
  import {useLocation} from "react-router-dom"

  const location = useLocation();
  const currentPath = location.pathname;
  const searchParams = location.search

useParams


  • url parameter의 key, value object를 보내줌
  • Ex)
  import { useParams } from “react-router-dom”;

  const { slug, order } = useParams();
profile
Full Stack Developer 📚

0개의 댓글