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...

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 first error, not the last

  • Fix syntax or logic issues

  • Reload after fixing

👉 A single JS error can completely block rendering.


2. React Router Not Configured for Production

Routing issues are one of the top causes of blank pages.

Common Problem

Your app works locally, but after deployment:

  • Home page works

  • Other routes show a blank page or 404

Why It Happens

React Router uses client-side routing, but the server doesn’t know those routes.

Fix (Example for Nginx)

location / { try_files $uri /index.html; }

This tells the server:

“Always serve index.html and let React handle routing.”


3. Wrong base or homepage Configuration

If your app is deployed in a subdirectory, React may look for assets in the wrong path.

Example Issue

Your app is deployed at:

https://example.com/app/

but React still tries to load assets from /.

Fix (Vite)

export default defineConfig({ base: "/app/" });

Fix (Create React App)

"homepage": "/app/"

Wrong base paths often result in:

  • Blank page

  • Failed JS/CSS loading


4. Build Files Not Loaded Correctly

If JavaScript files fail to load, React cannot run.

How to Check

  • Open Network tab in DevTools

  • Reload the page

  • Look for:

    • 404 errors

    • Failed .js or .css files

Fix

  • Make sure build folder is uploaded correctly

  • Ensure server points to the correct directory

  • Check file permissions on the server


5. Error in index.js or main.jsx

React starts rendering from a single entry point.

Common Mistakes

  • Wrong root element ID

  • File import errors

  • ReactDOM not mounting correctly

Correct Example

const root = ReactDOM.createRoot( document.getElementById("root") ); root.render(<App />);

If #root does not exist in index.html, nothing will render.


6. Environment Variable Issues

Environment variables often behave differently in production.

Common Issue

  • App works locally

  • Blank page in production

  • No obvious error

Why It Happens

  • Environment variable is missing

  • Wrong prefix (VITE_, REACT_APP_)

  • Variable undefined causes runtime error

Fix

  • Double-check .env files

  • Confirm variables exist in production

  • Avoid assuming variables are always defined


7. Strict Mode Revealing Hidden Bugs

React Strict Mode can cause effects to run twice in development.

This can expose:

  • Bad side effects

  • Incorrect assumptions in code

While Strict Mode does not affect production, it often reveals issues early.


8. Using Browser Cache After Deployment

Sometimes the app is fixed, but users still see a blank page.

Why?

  • Old JS files cached by the browser

  • New build references files that don’t exist locally

Fix

  • Hard refresh (Ctrl + Shift + R)

  • Clear cache

  • Use versioned builds (default in modern bundlers)


Step-by-Step Debugging Checklist

When facing a blank page:

  1. Check browser console

  2. Check network requests

  3. Verify routing configuration

  4. Confirm build paths

  5. Test with a simple component

  6. Inspect production environment variables

Following this order saves a lot of time.


Why This Happens So Often in React

React gives flexibility, but with that comes responsibility:

  • Routing is manual

  • Deployment matters

  • Server configuration is critical

Most blank page issues come from environment differences, not React itself.


Conclusion

A blank page in React is scary, but rarely mysterious. In most cases, it’s caused by routing, build paths, server configuration, or simple JavaScript errors.

Once you understand where React can fail, fixing these issues becomes straightforward. With the right debugging approach, you can resolve blank page problems quickly and confidently.

Comments

Popular posts from this blog

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...