Next Js Routing
Next Js Routing
Rendering converts the code you write into user interfaces. React and Next.js allow you to create
hybrid web applications where parts of your code can be rendered on the server or the client.
Rendering Environments
There are two environments where web applications can be rendered: the client and the server.
The client refers to the browser on a user's device that sends a request to a server for your
application code. It then turns the response from the server into a user interface.
The server refers to the computer in a data center that stores your application code, receives
requests from a client, and sends back an appropriate response.
Basic Routing
The Pages Router has a file-system based router built on concepts of pages. When a file is added
to the pages directory it's automatically available as a route.
Profile Page:
Localhost:3000/profile
Linking:
Create link in home page to move from home page to profile page and contact page.
return (
<main>
<h1>Basic Routing</h1>
return (
<main>
<h1>Basic Routing</h1>
</main>
);
}
Now to move from profile page to home page follow same steps
Profile/Page.js
Navigation:
Now create button in contact page to move from contact page to profile page.
Contact/Page.js
"use client"
import { useRouter } from "next/navigation";
export default function Contact()
{
const router = useRouter();
const move=(name)=>{
router.push(name)
}
return(
<main>
<h1> Contact Page</h1>
Click on button
Contact/Page.js
Nested Routes
To create a nested route, you can nest folders inside each other.
Src/app/profile/overview/page.js
Src/app/profile/page.js
Localhost:3000/profile/overview
Localhost:3000/profile