Next.js first page
creating the "hello world" of Next.js
Now that we have the foundation setup for building our Next.js app, let's build our first page:
Homepage
In the
app
folder, create a file calledpage.tsx
Alright, this gets as basic as it can get, now let's see it in action:
This will open up
localhost:3000
on the browserWe should see a simple page with "Home"
Every saved change we make to
page.tsx
will immediately hot reload the browser
Layout
We will notice that Next.js also generates a file called
layout.tsx
This file produces the root structure for our web app
We cannot delete or rename
layout.tsx
but we can make changes to it
At its barest, the root layout consists of
metadata
and theRootLayout
functionThe
metadata
comes with atitle
anddescription
for SEO purposesThe
RootLayout
carries the high-level DOM:html
andbody
{children}
, as we can guess, refers to the DOM inpage.tsx
Test the Tailwind styles (optional)
Let's also test the Tailwind we added previously
In
layout.tsx
import theglobal.css
file
Finally, in
app/page.tsx
let us test a few styles in the<h1>
tag:
Have a look at
localhost:3000
and, as opposed to "Home" in the default serif font", something like this should appear:
Last updated