2024.05.22 Today Yoonsung Learned

Ryany (윤성)·2024년 5월 23일
post-thumbnail

TIL

React Standard 4th 과제

EX1 문제

  • Browse Route 컴포넌트 생성
  • Home 컴포넌트는 Link 컴포넌트를 사용해서 Detail 컴포넌트로 이동하도록 하세요.
function Home() {
  return (
    <div>
      <h1>Home</h1>
      <Link to="/detail/1">Go to Detail 1</Link>
      <br />
      <Link to="/detail/2">Go to Detail 2</Link>
    </div>
  );
}
  • Detail 컴포넌트를 path parameter 로 id 를 받도록 하세요.
  • Detail 컴포넌트는 path parameter 로 받은 id 를 콘솔로그로 찍으세요.
function Detail() {
  const { id } = useParams();
  console.log("Detail ID:", id);

  return (
    <div>
      <h1>Detail Page</h1>
      <p>Detail ID: {id}</p>
    </div>
  );
}
profile
Junior Developer :>

0개의 댓글