React Router Dom의 Outlet 컴포넌트는 중첩 라우팅을 구현하는 데 매우 유용한 도구임
Outlet은 부모 라우트 요소에서 자식 라우트 요소를 렌더링하는 데 사용됨
이를 통해 중첩된 UI 구조를 쉽게 구현할 수 있으며, 특히 레이아웃을 공유하는 여러 페이지에서 유용함
사용 예시
import { Route, Routes, Outlet } from 'react-router-dom';
function Layout() {
return (
<div>
<header>공통 헤더</header>
<Outlet />
<footer>공통 푸터</footer>
</div>
);
}
function App() {
return (
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
<Route path="contact" element={<Contact />} />
</Route>
</Routes>
);
}