Next.js is a flexible React framework that gives you building blocks to create fast web applications.
In React, event names are camelCased
npm install react react-dom next //to get the base code in current folder
Server Components allow developers to better leverage server
infrastructure. For example, you can move data fetching to the server,
closer to your database.
all components inside the App Router are Server Components by default.
To improve the performance of your application, we recommend moving Client Components to the leaves of your component tree where possible.
For example, you may have a Layout that has static elements (e.g. logo, links, etc) and an interactive search bar that uses state.
Instead of making the whole layout a Client Component, move the interactive logic to a Client Component (e.g. <SearchBar />
) and keep your layout as a Server Component.
Good to know: In Next.js, during the initial page load, both the rendered result of Server Components from the above step and Client Components are pre-rendered on the server as HTML to produce a faster initial page load.
You cannot import a Server Component into a Client Component:
npm run dev // to execute the Next js and launch on the browser
Routing Concept:
You cannot import a Server Component into a Client Component:
Pages:
pages/index.js // home page
pages/blog.js // localhost/blog
pages/[blogid].js // blog/1
pages/product/index.js /product
pages/product/[productId]/index.js => /product/3
pages/product/[productId]/review/[reviewId].js => /product/3/review/4
For nested routes make folder [product]/[reviewid].js like this,
Catch ALL routes :
any url which has docs in the url will catch
pages/docs/[...params].js // docs/feature/2/content/1
pages/docs/[[...params]].js // docs/
Link Component Navigation:
import {Link} from 'next/link'
<Link><a href="/blog">Blog</a></Link>
How to concatenate string with value:
<Link><a href={`/product/${productid}`}>Blog</a></Link>
router.push(/product) // to redirect to another page
Pre Rendering :
Comments
Post a Comment