Building Portfolio with Next.js: Migrate to App Router

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
Search for a command to run...

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
No comments yet. Be the first to comment.
A series of my notes as I learn NextJS and Tailwind and build my portfolio website publicly.
Hello Friends ๐, So, I've added a navbar, footer, and metadata to my project. What I Learned Root Layout Root layout applies to all routes and is required. To make Navbar and Footer show on every page, we need to import and apply them in the root...
Hi friends ๐, I've been writing tech blog posts for a few years now. If you don't know me yet, English is my second language. My mother tongue is Indonesian, and I'm also surrounded by Dutch every da

I frequently receive messages from enthusiastic contributors who have completed 2 or 3 high-quality pull requests (PRs) in just 1 month. Theyโre proactive, their work is top-tier, and theyโve handled

A few months ago, I shared a story about building an automated open source portfolio using just my smartphone and an AI assistant while on vacation. My main goal was to stop the "spreadsheet struggle"

Recently, I read Bekah Hawrot Weigelโs blog post, "When 'Local' Went Global: The Pandemic Era of International Communities." As someone active in many online communities, I found it a bit sad, but I agree with her points and think they apply to open ...

Hacktoberfest is almost over. How has your contribution journey been so far? Are you confident about contributing to open source projects, or are you still struggling to find your way? If you're new to open source and still feel overwhelmed, that's c...

Hello Friends ๐,
As mentioned in the earlier post, I mistakenly read the Pages Router docs instead of the App Router. To use the App Router consistently, I have to move the files (routes) inside the pages folder into the app folder.
Next.js 13 introduces App Router built on React Server Component. It means that by default, React renders the whole application server-side. While with Pages Router, React renders the whole application client-side.
We can combine server and client components in App Router.
With server components, the client-side JavaScript bundle size is reduced, so the initial page loads faster. Read the section Why Serve Components? and Rendering in the docs for a more thorough explanation.
Anything related to the user's interactivity and React hooks still needs to render on the client side.
Think of keeping sensitive information on the server, working with data (fetching data, accessing backend resources directly), or working with large dependencies when choosing the server component.
All routes are live under the app folder in the App Router feature.
Each folder in the app folder defines a route.
Each folder should have a page.js file if we want to make the route public.
We can organize routes by grouping them in a special folder where the route will not be included in the URL path.
Why do we want to group the routes?
Our app or website might have many pages in the future with different purposes. For example, an e-commerce website usually has pages that the public can consume and pages that can only be accessed with authentication. We can organize the routes into folders, e.g., (shop)folder, (dashboard)folder, etc.
The convention to create a route group is by wrapping the folder name in parenthesis; (folderName).
I created a folder for each routeโabout, blog, and contactโin the app folder.
I moved all files in the pages to the app folder and put them in their folder.
I changed all files' names to page.js to be accessed publicly.
Because now I have three public foldersโroutesโand probably will have a dashboard in the future, I grouped the routes in the (websitePages) folderโI can't think of a better name for now ๐.
So currently, the app folder structure is like this:
app
โโโ (websitePages)
โ โโโ about
โ โ โโโ page.js
โ โโโ blog
โ โ โโโ page.js
โ โโโ contact
โ โโโ page.js
โโโ global.css
โโโ layout.js
โโโ page.js
The HTML had good styling before I moved the routes into the app folder. The <h1> and <h2> have the proper size for headings.
But the styling is gone after I moved them to the app folder. The headings are the same size as the paragraph. I provide a GIF for comparing App Router and Pages Router. I don't know yet what caused it. If you know what happened, drop a comment below ๐.

Pages โ Next.js docs
Route Groups โ Next.js docs
Incrementally adopt the Next.js App Router by Lee Robinson
NextJS App Router: Learn Modern Web Development by Josh tried coding
๐ผ๏ธ Credit cover image: unDraw
Thank you for reading! Last, you can find me on Twitter, Mastodon, and BlueSky. Let's connect! ๐