Skip to main content

Tutorial NextJS - Day 2

Hari 2 – Navigasi, Layout, & Dynamic Routing Setelah berhasil melakukan instalasi dan membuat halaman pertama di Hari 1 , pada Hari 2 ini kita akan membuat website menjadi lebih hidup. Kita akan belajar cara membuat menu navigasi agar bisa pindah-pindah halaman, membuat tampilan menu yang konsisten (Layout), dan membuat halaman artikel yang pintar (Dynamic Routing). Tutorial ini tetap menggunakan Windows + VS Code dan melanjutan project nextjs-basic dari hari sebelumnya. 1. Navigasi Antar Halaman ( <Link> ) Di HTML biasa, kita menggunakan tag <a> untuk berpindah halaman. Namun, di Next.js kita menggunakan komponen khusus bernama <Link> . Kenapa harus pakai <Link> ? Jika pakai <a> , layar akan berkedip (loading ulang) setiap pindah halaman. Dengan <Link> , perpindahan halaman terjadi instan tanpa refresh. 1.1 Edit Halaman Home Kita akan menambahkan tombol untuk pergi ke halaman About. Buka file src/app/page.tsx , lalu ganti isinya dengan kod...

Tutorial NextJS 30 Days

 

Hari 1 – Instalasi & Pengenalan Dasar Next.js (App Router)

Pada hari pertama ini, kita akan memulai dari nol, mulai dari persiapan environment, instalasi Next.js, hingga memahami konsep dasar routing dan membuat halaman pertama.

Tutorial ini menggunakan Windows + VS Code dan cocok untuk pemula.


1. Persiapan Environment

Sebelum menginstal Next.js, pastikan beberapa tools berikut sudah tersedia di komputer.

1.1 Install Node.js

Next.js membutuhkan Node.js untuk berjalan.

  • Unduh Node.js versi LTS (Long Term Support)

  • Instal seperti aplikasi biasa

  • Setelah selesai, restart komputer (penting agar PATH terbaca)

1.2 Cek Instalasi Node.js dan npm

Buka Terminal / PowerShell, lalu jalankan:

node -v npm -v

Jika muncul versi (contoh: v20.x.x), berarti Node.js berhasil terpasang.


2. Membuat Project Next.js

2.1 Masuk ke Folder Kerja

Masuk ke folder tempat kamu biasa menyimpan project web, misalnya:

cd %USERPROFILE%\Documents\web

Sesuaikan dengan folder masing-masing.


2.2 Inisialisasi Project Next.js

Jalankan perintah berikut:

npx create-next-app@latest nextjs-basic

Saat proses berjalan, akan muncul beberapa pertanyaan. Pilih opsi berikut:

  • TypeScript → Yes

  • ESLint → Yes

  • Tailwind CSS → Yes

  • Use src/ directory → Yes

  • Use App Router → Yes

  • Customize import alias → Yes (biarkan default @/*)

Tunggu hingga instalasi selesai.


3. Menjalankan Project

Masuk ke folder project:

cd nextjs-basic

Jalankan server development:

npm run dev

Buka browser dan akses:

http://localhost:3000

Jika halaman default Next.js muncul, berarti instalasi berhasil.


4. Struktur Folder Dasar

Setelah instalasi, struktur project akan terlihat seperti berikut:

nextjs-basic/ ├─ src/ │ ├─ app/ │ │ ├─ page.tsx │ │ ├─ layout.tsx │ │ └─ globals.css │ └─ ... ├─ public/ ├─ package.json

Penjelasan singkat:

  • app/ → tempat semua halaman Next.js

  • page.tsx → halaman utama (/)

  • layout.tsx → layout global

  • public/ → aset statis (gambar, icon)

Pada tahap awal, cukup fokus ke file page.tsx.


5. Konsep Routing di Next.js

Next.js menggunakan file-based routing, artinya:

  • Folder = URL

  • page.tsx = halaman

Contoh:

app/page.tsx → / app/about/page.tsx → /about

Tidak diperlukan konfigurasi routing manual seperti pada React biasa.


6. Membuat Halaman Home (Pertama)

6.1 Edit File page.tsx

Buka file:

src/app/page.tsx

Ganti isinya menjadi:

export default function Home() { return ( <div> <h1>Hello Next.js</h1> <p>Ini adalah hari pertama belajar Next.js</p> </div> ); }

Simpan file, lalu refresh browser.


7. Membuat Halaman About

7.1 Membuat Folder dan File

Buat folder dan file baru:

src/app/about/page.tsx

Isi dengan kode berikut:

export default function About() { return ( <div> <h1>About Page</h1> <p>Ini adalah halaman About pertama di Next.js</p> </div> ); }

Buka browser dan akses:

http://localhost:3000/about

Jika halaman tampil, berarti routing berbasis folder sudah berjalan dengan baik.


8. Apa yang Dipelajari di Hari Pertama

Pada hari pertama ini, kita telah mempelajari:

  • Cara menginstal Node.js

  • Cara membuat project Next.js

  • Menjalankan development server

  • Struktur folder dasar Next.js

  • Konsep routing berbasis folder

  • Membuat halaman Home dan About


9. Latihan Mandiri

Coba buat halaman baru tanpa melihat dokumentasi:

  1. Buat file:

    src/app/blog/page.tsx

    Akses URL yang dihasilkan.

  2. Buat file:

    src/app/user/profile/page.tsx

    Akses URL yang dihasilkan.

Latihan ini bertujuan untuk melatih pemahaman routing Next.js.

Comments

Popular posts from this blog

Why Your React App Shows a Blank Page (And How to Fix It)

Introduction One of the most frustrating problems when working with React JS is opening your app and seeing… nothing . No error message. No UI. Just a blank page . This issue happens frequently, especially after deployment or routing changes. In this article, we’ll explain why React apps show a blank page , the most common causes , and how to fix them step by step . What a “Blank Page” Usually Means in React A blank page usually means: React failed to render the UI JavaScript error stopped execution Routing or build configuration is broken Most of the time, the issue is not React itself , but how the app is configured. 1. JavaScript Error in the Console The first thing you should always check is the browser console. How to Check Open the app Right click → Inspect Open the Console tab If you see a red error message, React stopped rendering. Common Examples Cannot read property of undefined Unexpected token Module not found Fix Read the...

Nginx vs Apache: Which Web Server Should You Use on a VPS?

Introduction When setting up a VPS for hosting websites or applications, one of the first decisions you’ll face is choosing a web server. The two most popular options are Nginx and Apache . Both are powerful, widely used, and production-ready — but they work very differently. In this article, we’ll compare Nginx vs Apache , explain how each one works , highlight their strengths and weaknesses , and help you decide which web server is better for your VPS setup . What Is a Web Server? A web server is software that: Receives requests from browsers Processes those requests Serves HTML, CSS, JavaScript, or API responses Popular web servers include: Nginx Apache LiteSpeed Caddy Among them, Nginx and Apache dominate most VPS environments . What Is Apache? Apache has been around since the mid-1990s and was the most widely used web server for many years. How Apache Works Apache uses a process-based or thread-based model : Each request is handled by a p...

React Build vs Development Mode: What’s the Difference?

Introduction Many React developers are surprised when their app works perfectly during development — but behaves differently after deployment. Features break, routing fails, environment variables disappear, or performance changes dramatically. Most of these issues come from not understanding the difference between React’s development mode and production (build) mode . In this article, we’ll explain: What development mode really does What changes in production builds Why bugs appear only after deployment How to avoid common build-related mistakes What Is Development Mode in React? Development mode is what you use when running commands like: npm start npm run dev In this mode, React prioritizes developer experience , not performance. Key Characteristics of Development Mode Detailed error messages Helpful warnings Hot reloading (instant updates) Slower performance (on purpose) Extra checks for unsafe patterns Development mode helps you find bugs e...