@folderName
export default function Layout({
children,
sidebar,
}: {
children: ReactNode;
sidebar: ReactNode;
}) {
return (
<div>
<div>{sidebar}</div>
<div>{children}</div>
</div>
);
}
default.tsx
(.)book/[id]
()
: 소괄호 뒤의 경로를 인터셉트 하라는 표시.(/book/1)(.)
: 상대 경로 의미. 동일한 경로상에 있는 book/[id]의 값을 인터셉트 하겠다는 의미.(..)
: 한 단계 위의 경로.(..)(..)
: 두 단계 위의 경로.(...)
: app 폴더 바로 밑에 있는 경로.export default function Modal({ children }: { children: ReactNode }) {
const dialogRef = useRef<HTMLDialogElement>(null);
const router = useRouter();
useEffect(() => {
if (!dialogRef.current?.open) {
dialogRef.current?.showModal();
dialogRef.current?.scrollTo({
top: 0,
});
}
}, []);
return createPortal(
<dialog
onClose={() => router.back()}
onClick={(e) => {
// 모달의 배경이 클릭 되면 뒤로가기
if ((e.target as any).nodeName === "DIALOG") {
router.back();
}
}}
className={style.modal}
ref={dialogRef}
>
{children}
</dialog>,
document.getElementById("modal-root") as HTMLElement
// 모달이 렌더링 될 위치.(돔 위치)
);
}
// RootLayout.tsx
<div id='modal-root' />