Hello Friends π,
I executed the plan to add pages to the portfolio project. I love how convenient routing handling is in Next.js.
What I Learned
App Router
- In version 13, Next.js introduced the new App Router that is built on React Server Component. 
- 
π Special note: - In the docs, two features are available, App Router and Pages Router. We can choose between two from the dropdown menu at the top sidebar. We must keep in mind which tab we choose as each of them is unique.
- It's recommended to migrate to App Router to get the most out of React's latest features.
 
Pages
- 
Next.js uses a file-system-based router where folders are used to define routes. For example, if my appfolder has this structure:
 app βββ global.css βββ layout.js βββ page.js βββ blog βββ page.js βββ post-one.mdThen the route to post onewill bewebsite.com/blog/post-one.The breakdown of the route: - The page.jsunder theappfolder is the route to the first slash (/) afterwebsite.com.
- The page.jsthat lives under theblogfolder is the route toblog/.
- The post-one.mdis the route topost-one.
 Read the Routing Fundamentals section in the docs for a thorough explanation. 
- The 
- page.jsis used to make the route publicly accessible. The URL path from a folder without- page.jswon't be accessible to the public.
Link
- Like the anchor (<a>) tag in HTML,<Link>also uses thehrefattribute/prop. The difference is that we use<Link>if we want to navigate between routes in our application, and we use<a>when we want to navigate to an external URL path.
What I Did
- By default, there is a - page.jsfile in the- appfolder. This file used to be called- index.js. I use it as the homepage of the website. For now, it only shows the homepage title.
- I created a - pagesfolder in the root and added- about-me.js,- blog.js, and- contact.js. Β Like the homepage, there's only a title on every page for now.
- 
I want every page to have a link back to the homepage so I don't need to type the URL path every time. - 
Import the Link. 
 import Link from "next/link"
- 
Applied the link to get back to the homepage. 
 <p> Back to <Link href='/'>Homepage</Link> </p>
 
- 
Some Thoughts
Now as I'm writing this post, I think I messed up between the two featuresβApp Router and Pages Routerβin the docs π .
The Learn Next.js tutorial on the Next.js website uses the Pages Router. So I probably read theΒ Pages RouterΒ docs without switching to theΒ App Router. Because I'm using theΒ App Router, I think I should adjust something regarding the pages for the next step. Well, I need to reread the docs π.
Next Plan
- Read the docs and see if I should fix anything regarding the pages. 
- Create a navbar and a footer. 
Resources
πΌοΈ Credit cover image: unDraw
Thank you for reading! Last, you can find me on Twitter, Mastodon, and BlueSky. Let's connect! π
 
 
              
 
    
Top comments (0)