
노마드 코더님의 Next.js 시작하기 를 들으면서 배운 내용들을 정리해보겠습니다.
npm init -y 명령어를 입력한다.package.json 파일을 생성하며 모든 설정을 "YES"로 응답한다는 뜻이다.{
"name": "learn-nextjs14",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
{
"name": "learn-nextjs14",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "next dev"
},
"keywords": [],
"author": "",
"license": "MIT",
"description": "",
"dependencies": ""
}
npm install react@latest next@latest react-dom@latest
package-lock.json이라는 파일이 생성되고, package.json 파일의 dependencies를 봐도 "next": "^14.2.13",
"react": "^18.3.1",
"react-dom": "^18.3.1"
3가지 패키지의 최신 버전이 설치됨을 알 수 있다.


export default function helloWorld() {
return <h1>helloWorld</h1>;
}
이렇게 함수를 정의해주었다.
npm run dev라는 명령어로 개발모드를 실행시켜봤을때

우리는 타입스크립트의 의존성을 추가해준 적이 없기때문에, 자동으로 의존성이 설치되는 것을 볼 수 있다.

localhost:3000번을 들어가더라도 제대로 react page가 나오는 것을 볼 수 있다.
터미널에는

이렇게 우리가 layout.tsx를 생성해 놓지 않아서, 대신 생성해준 것도 볼 수 있다.
마지막으로 다음과 같은 git ignore 파일도 생성해주었다.
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
Next.js는 폴더를 사용하여 경로를 정의하는 파일 시스템 기반 라우터를 사용합니다.
각 폴더는 URL 세그먼트에 매핑되는 경로 세그먼트를 나타냅니다.

중첩된 경로를 만들려면 app/posts/page.tsx 이렇게 폴더를 서로 중첩하면 됩니다.
위와 같은 경로를 접근할 때는 localhost:3000/posts이렇게 접근하게 됩니다.
app/not-found.tsxexport default function notFound() {
return <h1>notFound</h1>;
}

app/components/navbar.tsx'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
export default function Navigation() {
const path = usePathname();
return (
<nav>
<ul>
<li>
<Link href="/">Home</Link> {path === '/' ? '🔥' : ''}
</li>
<li>
<Link href="/posts">posting</Link>
{path === '/posts' ? '🔥' : ''}
</li>
</ul>
</nav>
);
}

import Navigation from './components/navbar';
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<Navigation />
<body>{children}</body>
</html>
);
}
