How to Make a Landing Page With Next.js, Without Coding!

by jungmink623 in Circuits > Computers

40 Views, 1 Favorites, 0 Comments

How to Make a Landing Page With Next.js, Without Coding!

nextjs.png

In this guide we will go over how to make a very generic landing page for a website/web application using the Next.js framework. Next.js is a JavaScript framework developed by Vercel that allows developers to create web applications using React, another framework.

In most websites, the first page that users will interact with or see is the landing page. If you are planning on creating and hosting a website, this guide will be useful in guiding you through the steps to make your own generic landing page from scratch!

You will need a decent understanding of JavaScript/TypeScript, HTML/CSS, so I will be skipping over basics. however there any many tools available that help people develop their own websites without having to do much coding, which we will talk about as well. Otherwise, this project should take an hour, so work at your own pace.

Supplies

channels4_profile.jpg
npm-logo.png

For this project you will need two things:


  1. VS Code installed (any version works, but latest version is recommended)
  2. npm installed to install and manage the dependencies you will need for this project


VS Code is a source code editor that you will be doing most of the development in.

npm (Node Package Manager) is a package manager you will be using just to install and keep track of dependencies.

Initialize Your Environment

znPfq.png

First, you will want to create a Next.js app in VS Code. Start by opening a new project in VS Code. Then, open a new terminal using CTRL + `.


Type the following into the terminal:

npx create-next-app@latest


For the landing page we will be using Tailwind CSS to make design easier. We can install Tailwind by doing the following two commands:

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p


Find the tailwind.config.js file in the app root folder and add the following code to the file (replace everything):

/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",

// Or if using `src` directory:
"./src/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {},
},
plugins: [],
}


Finally, let's install shadcn/ui! shadcn/ui is a component library built on Tailwind CSS. The reason we are using shadcn/ui is so that rather than coding components on a website from scratch, such as the navigation bar, we can use a predefined component library that has a bunch of generic components ready to use. Think of it as using a template for a PowerPoint presentation. Let's install shadcn/ui using the following command:

npx shadcn@latest init

You will be asked a few questions to configure the components.


Congratulations! You have finished the setup. Now you can run:

npm run dev

And you should be able to run your app in your browser, ready to be worked on. For me, it runs on localhost:3000 by default, but check your terminal to see where it runs for yours.


Note: You can use Ctrl + C to kill the web application at any time, then simply run npm run dev to run it again!

The Navbar

Screenshot 2024-10-05 at 11.43.40 PM.png

A landing page on a website will typically have three or two main components. The Navbar (Navigation Bar) at the top of the page that helps you navigate the website, the Hero Section, containing all the content of the landing page, and the Footer, which is just the bar at the bottom with trademarks, extra links, etc.


For this step lets start by creating a Navbar component.


Let's use a Navbar from shadcn/ui's library using the following command:


npx shadcn@latest add navigation-menu


The Navbar should now be in your "components" folder. Feel free to edit the code as you wish.


Then, in your "app" folder, find page.tsx (or .jsx, depending on which configuration you did in Step 1. Replace all the contents of page.tsx with the following code:


import React from 'react';
import NavigationMenuItem from './components/navigation-menu';
function LandingPage() {
return (
<div>
<NavigationMenuItem />
</div>
);
}

export default LandingPage;


All we have done is added the Navbar to the page of the default route, which is just localhost:3000/ with nothing after the slash. So the Navbar should appear when the project is run immediately.


Test how it looks by running your project using:


npm run dev

The Hero Section

The Hero section is the body of the landing page, and the first thing you see on the page just under the Navbar!


Let's use a modified shadcn/ui Hero component, however feel free to make your own hero component! Execute this command:


npx shadcn@latest add "https://v0.dev/chat/b/b_0kqyGUPrt3f?token=eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..u8dYHEOwJ5dQ774z.OCFXfzeEMselp9Ev-t1gHzNpR_SNTFkauA5wh-DeVksK0iK2NNOkjy8f3vo.mqT2nDvsosSZA0OxSTWK3Q"


Then, add the Hero component onto the page.tsx underneath the Navbar:


import React from 'react';
import NavigationMenuItem from './components/navigation-menu';
function LandingPage() {
return (
<div>
<NavigationMenuItem />
<Hero />
</div>
);
}

export default LandingPage;


If you are not already running the page, run:


npm run dev


And you should see both the Navbar and the Hero section on the page!

The Footer

The footer is basically another bar like the Navbar, but at the bottom. You can put more hyperlinks, buttons, maybe copyrights/trademarks, or other information at the bottom in the footer. Lets use a generic footer with some text and place it at the bottom of the page!


Let's add a modified shadcn/ui footer component!

npx shadcn@latest add "https://v0.dev/chat/b/b_IQLlWOs6pJg?token=eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..iioLL1jykX0lucSa.tb2eNFT0ZSm5UeRKW78ERzdmC0PNRXePL7E_54_8itDIRpDoiOyA9iEQMuQ.KjYXjwMjChhIwbKwvo-R7g"


Now we add the component underneath the Hero in the page.tsx file:


import React from 'react';
import NavigationMenuItem from './components/navigation-menu';
function LandingPage() {
return (
<div>
<NavigationMenuItem />
<Hero />
<Footer />
</div>
);
}

export default LandingPage;



Conclusion

Screenshot 2024-10-18 at 10.35.04 PM.png

Your page.tsx in the app folder should now look like this:


import React from 'react';
import NavigationMenuItem from './components/navigation-menu';
import Hero from './components/Hero';
import Footer from './components/Footer';

function LandingPage() {
return (
<div>
<NavigationMenuItem />
<Hero />
<Footer />
</div>
);
}

export default LandingPage;


When you run:


npm run dev


You should now be able to see the landing page with the Navbar, Hero, and Footer components all on the page. For the example, I filled all the text fields with "xxx".


If you look at the code for each component individually in the "components" folder, you can edit the code however you wish to fit your needs.


Feel free to use ChatGPT or, my personal favorite tool, v0.dev (I used this tool for the Hero and Footer), and paste the code of any component, and ask to change it however you like. It is a quick and easy way to make edits to components and pages as a whole built with Next.js or React without having to do any coding!


Good luck!