layout.js
import './globals.css';
import Link from 'next/link';
export const metadata = {
title: 'Tutorials',
description: 'Generated by song',
}
export default async function RootLayout({ children }) {
const res = await fetch('http://localhost:9999/topics');
const topics = await res.json();
return (
<html>
<body>
<h1><Link href="/">WEB</Link></h1>
<ol>
{topics.map((topic)=>{
return <li key={topic.id}><Link href={`/read/${topic.id}`}>{topic.title}</Link></li>
})}
</ol>
{children}
<ul>
<li><Link href="/create">Create</Link></li>
<li><Link href="/update">Update</Link></li>
<li><Link href="/update/edit">Edit</Link></li>
<li><input type="button" value='delete'/></li>
</ul>
</body>
</html>
)
}
Read/[id]폴더의 page.js
export default async function Read(props) {
const res = await fetch(`http://localhost:9999/topics/${props.params.id}`);
const topic = await res.json();
return(
<>
<h2>title : {topic.title}</h2>
<p>{topic.body}</p>
</>
)
}
여기서 page.js에서 props를 이용해서 props.params.id 하는데 layout.js에서는 props를 전달하는 부분이 없는데 대체 어디서 전달하는거임?
Link는 props전달이 아닌데
children 말하는 거면 <tag1><children /></tag1> 이런 식으로 넣는 거임 - dc App
children이 tag1 안에 있는 컴포넌트 리스트임 - dc App
children아님
params.id 말하는거? - dc App
ㅇㅇ props.params.id 이게 어디서 넘어오는건지..
url이요.. 주석에 이미 써논거 같은데? Read/[id] 이거 - dc App
그니까 그게 어떻게 가능한거임 Read/[id] 이건 그냥 폴더구조인데
next.js가 알아서 routing해서 넣어주나보지 - dc App
예를들어
http://what.the.fuck/read?id=3
이면
해당 page.js의 props.searchParams.get('id') 이런식으로 들어감 - dc App
?? params는 알겠는데 searchParams는 뭐여 하
비슷한거 - dc App