<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khan Rabiul </title>
    <description>The latest articles on DEV Community by Khan Rabiul  (@khanrabiul).</description>
    <link>https://dev.to/khanrabiul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1632915%2Fcb70dba0-fefa-4507-be9c-904b6257287a.jpeg</url>
      <title>DEV Community: Khan Rabiul </title>
      <link>https://dev.to/khanrabiul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khanrabiul"/>
    <language>en</language>
    <item>
      <title>Next.js + TailwindCSS v4: How to Add Dark/Light Theme with Next-Themes</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Sat, 20 Dec 2025 13:53:07 +0000</pubDate>
      <link>https://dev.to/khanrabiul/nextjs-tailwindcss-v4-how-to-add-darklight-theme-with-next-themes-3c6l</link>
      <guid>https://dev.to/khanrabiul/nextjs-tailwindcss-v4-how-to-add-darklight-theme-with-next-themes-3c6l</guid>
      <description>&lt;p&gt;&lt;code&gt;TailwindCSS v4&lt;/code&gt; no longer maintains multiple config files-everything now goes inside a single &lt;code&gt;global.css&lt;/code&gt; file. This can make theming feel a bit challenging. In this guide, I'll show you how to easily set up light, dark, and even custom themes in your &lt;code&gt;Next.js&lt;/code&gt; project using &lt;code&gt;next-themes.&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 01: Initiate your project
&lt;/h3&gt;

&lt;h4&gt;
  
  
  👉 Install your Next.js project
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm create next-app my-project-name
pnpm install
pnpm dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  👉 Install Next Themes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm add next-themes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 02: Modify your &lt;code&gt;layout.tsx&lt;/code&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  👉 Wrap the application(children) with &lt;code&gt;&amp;lt;ThemeProvider&amp;gt;&amp;lt;/ThemeProvider&amp;gt;&lt;/code&gt;. In the following example, I keep all the default &lt;code&gt;Next.js&lt;/code&gt; code.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "next-themes";

const geistSans = Geist({
  variable: "--font-geist-sans",
  subsets: ["latin"],
});

const geistMono = Geist_Mono({
  variable: "--font-geist-mono",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: Readonly&amp;lt;{
  children: React.ReactNode;
}&amp;gt;) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      &amp;gt;
       &amp;lt;ThemeProvider&amp;gt;
         {children}
       &amp;lt;/ThemeProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  👉 Add attributes for &lt;code&gt;ThemeProvider&lt;/code&gt;.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ThemeProvider enableSystem={true} defaultTheme="system" &amp;gt;
{children}
&amp;lt;/ThemeProvider&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Attributes
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;enableSystem={true}&lt;/code&gt; ensures that your application can perform according to the user's device preference. By default, it is false. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;defaultTheme="system"&lt;/code&gt; defines which theme will be loaded on the first load of the application. &lt;/p&gt;

&lt;h4&gt;
  
  
  error
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add &lt;code&gt;suppressHydrationWarning&lt;/code&gt; attribute in &lt;code&gt;html&lt;/code&gt; tag. It will solve the error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en" suppressHydrationWarning&amp;gt;
      &amp;lt;body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      &amp;gt;
       &amp;lt;ThemeProvider enableSystem={true} defaultTheme="system"&amp;gt;
         {children}
       &amp;lt;/ThemeProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Remember that &lt;code&gt;ThemeProvider&lt;/code&gt; is not a &lt;code&gt;server&lt;/code&gt; &lt;code&gt;component&lt;/code&gt;. It is a &lt;code&gt;client&lt;/code&gt; component.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 03: Customize your color
&lt;/h3&gt;

&lt;h4&gt;
  
  
  👉 &lt;code&gt;global.css&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Add them to your &lt;code&gt;global.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import 'tailwindcss';

@custom-variant dark (&amp;amp;:where([data-theme=dark], [data-theme=dark] *));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To work with &lt;code&gt;tailwindcss v4&lt;/code&gt;, &lt;code&gt;@import 'tailwindcss'&lt;/code&gt; is required.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;@custom-variant dark (&amp;amp;:where([data-theme=dark], [data-theme=dark] *))&lt;/code&gt; line of code enables &lt;code&gt;dark&lt;/code&gt; classes in &lt;code&gt;HTML&lt;/code&gt; tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="bg-gray-300 dark:bg-amber-500"&amp;gt;
    &amp;lt;h2 className="text-xl text-teal-600"&amp;gt;Next Theme With Tailwindcss v4
    &amp;lt;/h2&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the dark theme is selected, the style applied for &lt;code&gt;dark&lt;/code&gt; mode will be applied. In the example, &lt;code&gt;bg-amber-500&lt;/code&gt; will be applied for the &lt;code&gt;dark&lt;/code&gt; theme.&lt;/p&gt;

&lt;p&gt;Now add colors &lt;code&gt;variables&lt;/code&gt; as you prefer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@theme {
  /* theme background color */
  /* Light mode default */
  --bg-color-light-default: hsl(220, 14%, 96%);
 /* Dark mode default */
  --bg-color-dark-default: hsl(207, 95%, 8%);  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the &lt;code&gt;theme&lt;/code&gt;, &lt;code&gt;directive&lt;/code&gt; as you use in &lt;code&gt;tailwindcss&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Add &lt;code&gt;:root&lt;/code&gt; selector for each theme. The application will maintain background colors from the root of your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root[data-theme="light"] {
  background-color: var(--color-background-light);
}

:root[data-theme="dark"] {
  background-color: var(--color-background-dark);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 04: Add theme toggler button
&lt;/h3&gt;

&lt;p&gt;To change different themes, I am going to use &lt;code&gt;lucid react&lt;/code&gt; icons library.&lt;br&gt;
As it is a user's interactive button, it will be a &lt;code&gt;client component&lt;/code&gt;. I make it different component for it, named &lt;code&gt;ThemetogglerBtn.tsx&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm install lucide-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ThemetogglerBtn.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';

import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
import { Sun, Moon } from 'lucide-react';

export default function ThemeSwitcher() {
  const [mounted, setMounted] = useState(false);
  const { theme, setTheme, resolvedTheme } = useTheme();

  useEffect(() =&amp;gt; {
    setMounted(true);
  },
    []);

const toggleTheme = () =&amp;gt; {
  setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')
}

  if (!mounted) {
    return (
      &amp;lt;div className="w-10 h-10 flex items-center justify-center rounded-full bg-gray-200 dark:bg-gray-700"&amp;gt;
      &amp;lt;/div&amp;gt;
    )
  }

  const currentIcon = resolvedTheme === 'dark' ? (&amp;lt;Sun size={24} className="text-yellow-500" /&amp;gt;) :
  (&amp;lt;Moon size={24} strokeWidth={2} className="text-gray-700"/&amp;gt;);

  return (
    &amp;lt;button
      onClick={toggleTheme}
      className="p-2 rounded-full flex items-center           justify-center transition-colors bg-[--bg-light] hover:bg-[--bg-light] dark:hover:bg-[--bg-light]"
      aria-label={resolvedTheme === 'dark' ? "Switch to light theme" : "Switch to dark theme"}
      title={resolvedTheme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'}
    &amp;gt;
      {currentIcon}
      &amp;lt;span className="sr-only"&amp;gt;Theme switcher button&amp;lt;/span&amp;gt;
    &amp;lt;/button&amp;gt;
  )
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  👉 &lt;code&gt;useTheme&lt;/code&gt; &lt;code&gt;hook&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;import&lt;/code&gt; &lt;code&gt;use-theme()&lt;/code&gt; from &lt;code&gt;next-themes&lt;/code&gt; &lt;br&gt;
&lt;code&gt;const {theme, setTheme, resolvedTheme = useTheme()&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  🌗 &lt;code&gt;theme&lt;/code&gt; shows the current selected theme.
&lt;/h5&gt;
&lt;h5&gt;
  
  
  🌗 &lt;code&gt;setTheme&lt;/code&gt;, with the setter function, we can set a new theme.
&lt;/h5&gt;
&lt;h5&gt;
  
  
  🌗 &lt;code&gt;resolvedTheme&lt;/code&gt;: It acknowledges the system presence theme. Currently, is it &lt;code&gt;dark&lt;/code&gt;or &lt;code&gt;light&lt;/code&gt; theme active on the user's device?
&lt;/h5&gt;
&lt;h4&gt;
  
  
  👉 &lt;code&gt;mounted&lt;/code&gt; &lt;code&gt;state&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;In &lt;code&gt;next.js&lt;/code&gt; &lt;code&gt;useTheme&lt;/code&gt; may mismatch hydration for &lt;code&gt;client&lt;/code&gt; and &lt;code&gt;server&lt;/code&gt; side components. To avoid this, we use &lt;code&gt;mounted&lt;/code&gt; &lt;code&gt;state&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [mounted, setMounted] = useState(false);
useEffect(() =&amp;gt; {
setMounted(true)
},[])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Initially &lt;code&gt;mounted = false&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After rendering &lt;code&gt;client&lt;/code&gt; &lt;code&gt;component&lt;/code&gt;, it becomes &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;So it ensures &lt;code&gt;theme toggler&lt;/code&gt; works only in &lt;code&gt;client side&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  🌗 &lt;code&gt;toggleTheme&lt;/code&gt; theme toggler function
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const toggleTheme =() =&amp;gt; {
setTheme(resolvedTheme = 'dark' ? 'light' : 'dark');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If the current value of &lt;code&gt;resolvedTheme === dark&lt;/code&gt;, then it will change the theme to &lt;code&gt;light&lt;/code&gt;. And if &lt;code&gt;resolvedTheme === light&lt;/code&gt;, it will change to &lt;code&gt;dark&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  🌗 Change icon
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentIcon = resolvedTheme === `dark` ?
(&amp;lt;Sun size={24} className='text-yellow-500' /&amp;gt;) 
: &amp;lt;Moon size={24} className='text-gray-700'/&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;dark&lt;/code&gt; mode is enabled, it will render &lt;code&gt;Sun&lt;/code&gt; icon. And for &lt;code&gt;light&lt;/code&gt; mode &lt;code&gt;Moon&lt;/code&gt; icon.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  🌗 UI in &lt;code&gt;button&lt;/code&gt;
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button onClick={toggleTheme}&amp;gt;
{currentIcon}
 &amp;lt;span className="sr-only"&amp;gt;Theme switcher button&amp;lt;/span&amp;gt;
&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Clicking on the button activates &lt;code&gt;toggleTheme&lt;/code&gt; &lt;code&gt;function&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{currentIcon}&lt;/code&gt;: &lt;code&gt;renders&lt;/code&gt; icon.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;span className="sr-only"&amp;gt;Theme switcher button&amp;lt;/span&amp;gt;&lt;/code&gt;: &lt;code&gt;sr-only&lt;/code&gt; is a good practice for accessibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ✅ At a glance
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;code&gt;next-themes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Wrap app with &lt;code&gt;&amp;lt;ThemeProvider&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Configure &lt;code&gt;global.css&lt;/code&gt; with &lt;code&gt;@custom-variant dark&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add theme toggler button with &lt;code&gt;useTheme&lt;/code&gt; hook&lt;/li&gt;
&lt;li&gt;Enjoy smooth dark/light theme switching 🎉&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>nextjs</category>
      <category>tailwindcss</category>
      <category>webdev</category>
      <category>darkmode</category>
    </item>
    <item>
      <title>Parallel Routes in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Mon, 26 May 2025 16:10:00 +0000</pubDate>
      <link>https://dev.to/khanrabiul/parallel-routes-in-nextjs-2a5b</link>
      <guid>https://dev.to/khanrabiul/parallel-routes-in-nextjs-2a5b</guid>
      <description>&lt;p&gt;&lt;code&gt;Parallel&lt;/code&gt; &lt;code&gt;routes&lt;/code&gt; is a powerful feature in &lt;code&gt;Next.js&lt;/code&gt;. It allows you to render one or more independent pages in the same &lt;code&gt;layout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnbin1pyl9di7wsg455z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnbin1pyl9di7wsg455z.png" alt="parallel routes" width="700" height="614"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;Slots&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;parallel&lt;/code&gt; &lt;code&gt;routes&lt;/code&gt; are called &lt;code&gt;slots&lt;/code&gt;. &lt;code&gt;Slots&lt;/code&gt; are passed as props to the parent &lt;code&gt;layout&lt;/code&gt;. &lt;code&gt;Slots&lt;/code&gt; are defined with the &lt;code&gt;@foldername&lt;/code&gt; convention.&lt;/p&gt;




&lt;h3&gt;
  
  
  How to Create &lt;code&gt;Parellel&lt;/code&gt; &lt;code&gt;Routes&lt;/code&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Make Folder Structure
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parallel-routes/app/
├── components/
│   ├── Footer.tsx
│   └── Header.tsx
├── dashboard/
│   ├── @oldusers/
│   │   └── page.tsx
│   ├── layout.tsx
│   └── page.tsx
├── globals.css
├── layout.tsx
└── page.tsx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make the &lt;code&gt;dashboard&lt;/code&gt; &lt;code&gt;route&lt;/code&gt; accessible, create a &lt;code&gt;page.tsx&lt;/code&gt; file in the &lt;code&gt;dashboard&lt;/code&gt; directory. Define your individual &lt;code&gt;slots&lt;/code&gt; under the &lt;code&gt;dashboard&lt;/code&gt; directory. For every individual &lt;code&gt;slot&lt;/code&gt; create a &lt;code&gt;page.tsx&lt;/code&gt; file in it. &lt;/p&gt;




&lt;h4&gt;
  
  
  Step 2: Define &lt;code&gt;slots&lt;/code&gt; in the &lt;code&gt;layout&lt;/code&gt;.
&lt;/h4&gt;

&lt;p&gt;Inject your &lt;code&gt;slots&lt;/code&gt; in the dashboard's &lt;code&gt;layout&lt;/code&gt;. As slots are received as &lt;code&gt;props&lt;/code&gt; destructure and use them in the &lt;code&gt;layout&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Dashboard ({children ,oldusers}: {
  children: React.ReactNode;
  oldusers: React.ReactNode;
}) {
  return(
    &amp;lt;&amp;gt;
    &amp;lt;main className="h-screen flex items-center justify-center"&amp;gt;
      {children}
      {oldusers}
    &amp;lt;/main&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should see your &lt;code&gt;dashboard&lt;/code&gt; and &lt;code&gt;slots&lt;/code&gt; by navigating &lt;a href="//.../dashboard"&gt;.../dashboard&lt;/a&gt;. But one interesting thing you may notice is. In your browser's &lt;code&gt;URL&lt;/code&gt;, there is no &lt;code&gt;balance&lt;/code&gt; or other &lt;code&gt;slots&lt;/code&gt; &lt;code&gt;routes&lt;/code&gt; in the &lt;code&gt;URL&lt;/code&gt;. Because &lt;code&gt;slots&lt;/code&gt; does not act as a path. &lt;br&gt;
If you want to create more &lt;code&gt;slots&lt;/code&gt;, inject them into your &lt;code&gt;layout&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Dashboard ({children ,oldusers, newusers}: {
  children: React.ReactNode;
  oldusers: React.ReactNode;
  newusers: React.ReactNode;
}) {
  return(
    &amp;lt;&amp;gt;
    &amp;lt;main&amp;gt;
      {children}
      {oldusers}
      {newusers}
    &amp;lt;/main&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Handling &lt;code&gt;error&lt;/code&gt; and &lt;code&gt;loading&lt;/code&gt; for &lt;code&gt;slots&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;Next.js&lt;/code&gt; gives flexibility in handling error&lt;code&gt;and&lt;/code&gt;loading&lt;code&gt;. To handle&lt;/code&gt;error&lt;code&gt;and&lt;/code&gt;loading&lt;code&gt;for a&lt;/code&gt;page&lt;code&gt;we have to create&lt;/code&gt;error.tsx&lt;code&gt;and&lt;/code&gt;loading.tsx&lt;code&gt;in the same directory as that&lt;/code&gt;page&lt;code&gt;.&lt;/code&gt;Solots&lt;code&gt;are individual&lt;/code&gt;page&lt;code&gt;, we can handle&lt;/code&gt;error&lt;code&gt;and&lt;/code&gt;loading&lt;code&gt;for every&lt;/code&gt;slot&lt;code&gt;separately. &lt;br&gt;
Create&lt;/code&gt;error.tsx&lt;code&gt;in you&lt;/code&gt;slots&lt;code&gt;(&lt;/code&gt;&lt;a class="mentioned-user" href="https://dev.to/balance"&gt;@balance&lt;/a&gt;`) directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
'use client'&lt;/p&gt;

&lt;p&gt;import { useEffect } from "react";&lt;/p&gt;

&lt;p&gt;const Error = ({ error, reset }) =&amp;gt; {&lt;br&gt;
  useEffect(() =&amp;gt; {&lt;br&gt;
    console.error(error)&lt;br&gt;
  }, [error])&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
      &lt;h2&gt;Something went wrong!&lt;/h2&gt;
&lt;br&gt;
      &lt;h3&gt;Reason: {error.message}&lt;/h3&gt;
&lt;br&gt;
      
        className="bg-black text-white p-1 rounded-md m-auto"&lt;br&gt;
        onClick={() =&amp;gt; reset()}&lt;br&gt;
      &amp;gt;&lt;br&gt;
        Try again&lt;br&gt;
      &lt;br&gt;
    &lt;br&gt;
  );&lt;br&gt;
};

&lt;p&gt;export default Error;&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
You can handle your component as you want. &lt;/p&gt;




&lt;h3&gt;
  
  
  Create &lt;code&gt;routes&lt;/code&gt; for &lt;code&gt;slots&lt;/code&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Step 1: Import &lt;code&gt;Link&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import Link from 'next/link'&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Create a &lt;code&gt;Link&lt;/code&gt; &lt;code&gt;Component&lt;/code&gt;. That will redirect to the &lt;code&gt;page&lt;/code&gt;.
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import Link from 'next/link'&lt;/p&gt;

&lt;p&gt;New Users&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Where to create the new &lt;code&gt;page&lt;/code&gt;.
&lt;/h4&gt;

&lt;p&gt;If you think our route is &lt;code&gt;/dashboard/newusers/&lt;/code&gt; so you have to create a directory under &lt;code&gt;dashboard&lt;/code&gt; and a &lt;code&gt;page&lt;/code&gt; in it. Then you are wrong. You have to create a directory in the &lt;code&gt;slot&lt;/code&gt; from where the user can go to the &lt;code&gt;route&lt;/code&gt;.&lt;br&gt;
In our case, we have a &lt;code&gt;slot&lt;/code&gt; named &lt;code&gt;oldusers&lt;/code&gt;. We will make a folder &lt;code&gt;newusers&lt;/code&gt; and a &lt;code&gt;page&lt;/code&gt; in the &lt;code&gt;oldusers&lt;/code&gt; directory. As we do for creating &lt;code&gt;routes&lt;/code&gt; in &lt;code&gt;Next.js&lt;/code&gt;.&lt;br&gt;
Now you can go to the &lt;code&gt;newusers&lt;/code&gt; page from the &lt;code&gt;oldusers&lt;/code&gt; &lt;code&gt;slot&lt;/code&gt; by clicking the &lt;code&gt;Link/button&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: &lt;code&gt;404 Not found&lt;/code&gt; page.
&lt;/h4&gt;

&lt;p&gt;When users reload on &lt;code&gt;/dashboard/newusers/&lt;/code&gt; page. Users will be redirected to the &lt;code&gt;Not found page&lt;/code&gt;. To prevent this issue, we need to use the &lt;code&gt;default.js/jsx/tsx..&lt;/code&gt; file in our directory.&lt;br&gt;
In the parent(&lt;code&gt;dashboard&lt;/code&gt;) create a &lt;code&gt;default.tsx&lt;/code&gt; file. And style it as it looks like with all &lt;code&gt;slots&lt;/code&gt;. Also, we need to use the &lt;code&gt;default.tsx&lt;/code&gt; component for every single &lt;code&gt;slot&lt;/code&gt; where there are new &lt;code&gt;routes&lt;/code&gt; are available. The &lt;code&gt;default.tsx&lt;/code&gt; component will look like the slot looks.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
app/&lt;br&gt;
├── dashboard/&lt;br&gt;
│   ├── layout.tsx&lt;br&gt;
│   ├── page.tsx&lt;br&gt;&lt;br&gt;
│   ├── default.tsx&lt;br&gt;&lt;br&gt;
│   ├── @oldusers/&lt;br&gt;&lt;br&gt;
│   │   ├── default.tsx&lt;br&gt;&lt;br&gt;
│   │   └── newusers/&lt;br&gt;&lt;br&gt;
│   │       └── page.tsx&lt;br&gt;&lt;br&gt;
│   └── @anotherSlot/&lt;br&gt;&lt;br&gt;
│       └── default.tsx&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now users if users refresh or directly access the &lt;code&gt;/dashboard/newusers/&lt;/code&gt; link, they will see your &lt;code&gt;pages&lt;/code&gt;/&lt;code&gt;slots&lt;/code&gt;.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>parellelroutes</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Templates in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Fri, 23 May 2025 14:28:43 +0000</pubDate>
      <link>https://dev.to/khanrabiul/templates-in-nextjs-167a</link>
      <guid>https://dev.to/khanrabiul/templates-in-nextjs-167a</guid>
      <description>&lt;p&gt;In &lt;code&gt;Next.js&lt;/code&gt; &lt;code&gt;layout.tsx&lt;/code&gt; is a shared &lt;code&gt;UI&lt;/code&gt; component between &lt;code&gt;routes&lt;/code&gt;. &lt;code&gt;layout.tsx&lt;/code&gt; never &lt;code&gt;rerenders&lt;/code&gt; when we navigate from one &lt;code&gt;route&lt;/code&gt; to another. We use &lt;code&gt;layout&lt;/code&gt; to render static elements that are not supposed to be changed. Like, the &lt;code&gt;Header&lt;/code&gt;, &lt;code&gt;Footer&lt;/code&gt;, etc. It means, &lt;code&gt;layout&lt;/code&gt; keeps your component/pages or &lt;code&gt;UI&lt;/code&gt; the same way and renders the &lt;code&gt;page.tsx&lt;/code&gt; in it as &lt;code&gt;children&lt;/code&gt;, if you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuaxc8xmv5l7z7j2uqn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuaxc8xmv5l7z7j2uqn9.png" alt="layout example" width="723" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Difference between &lt;code&gt;layout&lt;/code&gt; and &lt;code&gt;template&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Just like &lt;code&gt;layout&lt;/code&gt; &lt;code&gt;template&lt;/code&gt; also wraps the &lt;code&gt;pages&lt;/code&gt; and &lt;code&gt;components&lt;/code&gt; as &lt;code&gt;children&lt;/code&gt;. But the main difference between &lt;code&gt;layout&lt;/code&gt; and &lt;code&gt;template&lt;/code&gt; is, &lt;code&gt;layout&lt;/code&gt; can keep the current state, but &lt;code&gt;template&lt;/code&gt; can't. That's why &lt;code&gt;layout&lt;/code&gt; does not change the &lt;code&gt;UI&lt;/code&gt; or does not manipulate the &lt;code&gt;DOM&lt;/code&gt;. On the other hand, &lt;code&gt;template&lt;/code&gt; does not hold the &lt;code&gt;state value&lt;/code&gt;. It changes the &lt;code&gt;state&lt;/code&gt; rerenders the &lt;code&gt;UI&lt;/code&gt;, and manipulates the &lt;code&gt;DOM&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Creating a &lt;code&gt;template&lt;/code&gt; is very simple. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a file named &lt;code&gt;template.tsx/jsx/js..&lt;/code&gt; in your desired directory.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;template&lt;/code&gt;, returning a &lt;code&gt;React component&lt;/code&gt; is compulsory.&lt;/li&gt;
&lt;li&gt;Do as you do in &lt;code&gt;layout.tsx&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import SignUp from './signup';

export default function MyTemplate({ children }: { children: React.ReactNode }) {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;SignUp /&amp;gt;
      {children}
    &amp;lt;/main&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, don't use &lt;code&gt;template&lt;/code&gt; for static assets. Use it for where &lt;code&gt;state&lt;/code&gt; needs to be changed and rerender the component.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;'use client'&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes you may need to use &lt;code&gt;'use client'&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you use any &lt;code&gt;React&lt;/code&gt; &lt;code&gt;hook&lt;/code&gt; or &lt;code&gt;state&lt;/code&gt; (&lt;code&gt;useState&lt;/code&gt;, useEffect) in your &lt;code&gt;template&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Attaches &lt;code&gt;event handlers&lt;/code&gt; or relies on browser &lt;code&gt;APIs&lt;/code&gt; (&lt;code&gt;window&lt;/code&gt;, &lt;code&gt;document&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Imports other Client Components (e.g., a &lt;code&gt;carousel&lt;/code&gt;, &lt;code&gt;chart&lt;/code&gt;, or &lt;code&gt;provider&lt;/code&gt;) &lt;/li&gt;
&lt;li&gt;Once &lt;code&gt;"use client"&lt;/code&gt; is present, all imports become part of the client bundle.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Link and its props in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Sun, 18 May 2025 15:17:01 +0000</pubDate>
      <link>https://dev.to/khanrabiul/link-and-its-props-in-nextjs-44bo</link>
      <guid>https://dev.to/khanrabiul/link-and-its-props-in-nextjs-44bo</guid>
      <description>&lt;h2&gt;
  
  
  In this article we will describe Next.js Link and its props
&lt;/h2&gt;

&lt;p&gt;Link is primarily used to navigate between routes in Next.js. It is a React component that extends the HTML &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element. It provides client-side navigation and prefetching facilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✍️ How to use Link in Next.js
&lt;/h3&gt;

&lt;p&gt;To use Link in Next.js we need to import it from &lt;code&gt;next/link&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can use it in UI. &lt;em&gt;href&lt;/em&gt; is required. So we have to pass a value for it. The value is the routes where we want to navigate. Here, by clicking the button users will be navigated to &lt;em&gt;about&lt;/em&gt; page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link';
export default function Home() {
  return (
    &amp;lt;div&amp;gt;
      Welcome to the Home page
      &amp;lt;div&amp;gt;
        &amp;lt;Link href="/about"&amp;gt;
          &amp;lt;button className='px-3 py-2 bg-blue-600 text-white rounded-md'&amp;gt;Go to About Page&amp;lt;/button&amp;gt;
        &amp;lt;/Link&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ✍️ Link component has some important props:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;href&lt;/li&gt;
&lt;li&gt;replace&lt;/li&gt;
&lt;li&gt;scroll&lt;/li&gt;
&lt;li&gt;prefetch&lt;/li&gt;
&lt;li&gt;legacyBehavior&lt;/li&gt;
&lt;li&gt;passHref&lt;/li&gt;
&lt;li&gt;shallow&lt;/li&gt;
&lt;li&gt;locale&lt;/li&gt;
&lt;li&gt;onNavigate&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;NB:&lt;/em&gt;&lt;/strong&gt; Only &lt;strong&gt;&lt;em&gt;href&lt;/em&gt;&lt;/strong&gt; is required and rest are optional.&lt;/p&gt;

&lt;h4&gt;
  
  
  👉 href: We have described it before.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  👉 replace
&lt;/h4&gt;

&lt;p&gt;It is optional, and the default value is false. When we add &lt;code&gt;replace&lt;/code&gt;, the value is settled to true. It means the browser's history is replaced with a new URL. Now, users can not go to the previous page by clicking the browser's back button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link';

export default function Home() {
  return (&amp;lt;&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;nav className="bg-gray-800 p-4"&amp;gt;
        &amp;lt;ul className="flex space-x-4"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/"&amp;gt;
              Home
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/about" &amp;gt;
              About
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/contactus"&amp;gt;
              Contact
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/nav&amp;gt;
      &amp;lt;div&amp;gt;
        Welcome to Home page
        &amp;lt;div className="space-y-8"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/about" replace&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to About Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/contactus"&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contactus Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div &amp;gt;

  &amp;lt;/&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is happening now? As we used &lt;code&gt;replace&lt;/code&gt; props in &lt;code&gt;Link&lt;/code&gt; component. If the user navigates to the about page by clicking the button from the &lt;strong&gt;&lt;em&gt;Home Page&lt;/em&gt;&lt;/strong&gt;. The user can not get back to to &lt;strong&gt;&lt;em&gt;Home Page&lt;/em&gt;&lt;/strong&gt;(previous page).&lt;/p&gt;

&lt;h5&gt;
  
  
  Where/when to use
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;login/logout page: After login or logout the user will be redirected to the &lt;strong&gt;Home Page&lt;/strong&gt;. From there he/she should not -back- to the login or logout page again. &lt;/li&gt;
&lt;li&gt;form submission: After submitting a form, the user will be redirected to the -Welcome Page- and will not be allowed to &lt;em&gt;back&lt;/em&gt; to the form submission page. &lt;/li&gt;
&lt;li&gt;And many more places where users are not allowed to back to the previous page.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  👉 scroll
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;scroll&lt;/code&gt; props control the viewport behavior. If &lt;code&gt;scroll={true}&lt;/code&gt; is true, users will see the component/page in his/her viewport. If not visible in the viewport, Next.js will scroll to the top of the first page element. The default value is &lt;em&gt;true&lt;/em&gt;. If you want to disable the behavior, set &lt;code&gt;scroll={false}&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link';

export default function Home() {
  return (&amp;lt;&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;nav className="bg-gray-800 p-4"&amp;gt;
        &amp;lt;ul className="flex space-x-4"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/"&amp;gt;
              Home
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/about" &amp;gt;
              About
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/contactus"&amp;gt;
              Contact
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/nav&amp;gt;
      &amp;lt;div&amp;gt;
        Welcome to Home page
        &amp;lt;div className="space-y-8"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/about" scroll={true}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to About Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/contactus" scroll={false}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contact us Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div &amp;gt;

  &amp;lt;/&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  👉 Where to use
&lt;/h5&gt;

&lt;p&gt;If you have a huge list on your page, or the page is an infinite scroll page, and you want to hold the position of the viewport. So that users can return to the same viewport after navigating other pages, set &lt;code&gt;scroll={false}&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 prefetch
&lt;/h4&gt;

&lt;p&gt;By prefetching, we mean preloading the JavaScript code, static assets, and data required for server-side rendering of the page associated with the link. Next.js automatically prefetches routes in production when a &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component enters the user’s viewport.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link';

export default function Home() {
  return (&amp;lt;&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;nav className="bg-gray-800 p-4"&amp;gt;
        &amp;lt;ul className="flex space-x-4"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/"&amp;gt;
              Home
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/about" &amp;gt;
              About
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/contactus"&amp;gt;
              Contact
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/nav&amp;gt;
      &amp;lt;div&amp;gt;
        Welcome to Home page
        &amp;lt;div className="space-y-8"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/about" prefetch={true}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to About Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/contactus" prefetch={true}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contact Us Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div &amp;gt;

  &amp;lt;/&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the example, prefetch happens when users enter the home page as the link component is associated. If users click the button, the component will be shown immediately as it is loaded in the background.&lt;br&gt;
If &lt;em&gt;&lt;code&gt;prefetch={false}&lt;/code&gt;&lt;/em&gt; is seated, the linked component will never be prefetched until users enter the page/component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link';

export default function Home() {
  return (&amp;lt;&amp;gt;

    &amp;lt;div&amp;gt;
      &amp;lt;nav className="bg-gray-800 p-4"&amp;gt;
        &amp;lt;ul className="flex space-x-4"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/"&amp;gt;
              Home
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/about" &amp;gt;
              About
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;Link href="/contactus"&amp;gt;
              Contact
            &amp;lt;/Link&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/nav&amp;gt;
      &amp;lt;div&amp;gt;
        Welcome to Home page
        &amp;lt;div className="space-y-8"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/about" prefetch={true}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to About Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div&amp;gt;
            &amp;lt;Link href="/contactus" prefetch={false}&amp;gt;
              &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contact Page
              &amp;lt;/button&amp;gt;
            &amp;lt;/Link&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div &amp;gt;

  &amp;lt;/&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the example, -about us- page will be prefetched when users enter the -home page-, but the -contact us page- will not. -contact us- page will be fetched when users click on the -&lt;code&gt;Link&lt;/code&gt;- component.&lt;br&gt;
Prefetching is disabled in development mode to avoid unnecessary network activity during hot reloads.&lt;/p&gt;
&lt;h5&gt;
  
  
  👉 Where to use
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;-&lt;code&gt;prefetch&lt;/code&gt;- gives smooth page navigation.&lt;/li&gt;
&lt;li&gt;Balance Bandwidth: Excessive prefetching can overwhelm network resources. Use -&lt;code&gt;prefetch={false}&lt;/code&gt;- on rarely visited or large routes.&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  👉 legacyBehavior
&lt;/h4&gt;

&lt;p&gt;An &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element is no longer required as a child of &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt;. &lt;br&gt;
&lt;strong&gt;Example wrong way&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;Link &amp;gt;
       &amp;lt;a href=""&amp;gt;
           &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                  Go to Contactus Page
           &amp;lt;/button&amp;gt;
        &amp;lt;/a&amp;gt;
   &amp;lt;/Link&amp;gt;
&amp;lt;/div&amp;gt;          
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example right way&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;Link href="/contactus"&amp;gt;
    &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contact Page
    &amp;lt;/button&amp;gt;
  &amp;lt;/Link&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt;_ &lt;em&gt;Do not use &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag.&lt;/em&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 passHref
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;passHref&lt;/code&gt; is used to pass the &lt;code&gt;href&lt;/code&gt; prop to its child in Next.js via the &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component. This is important when the child of &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; is a custom component that wraps an anchor tag &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 shallow
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;shallow&lt;/code&gt; props let us update the path of the current page without running any of Next.js' data fetching methods. The default value is &lt;em&gt;false&lt;/em&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 locale
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;locale&lt;/code&gt; prop is used to navigate users to different versions of a webpage based on the user's preferred locale.&lt;br&gt;
&lt;code&gt;next.config.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  i18n: {
    locales: ['en', 'bn'],
    defaultLocale: 'en',
  },
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Link href="/about" locale={true}&amp;gt;
  About Page (locale true)
&amp;lt;/Link&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As locale is true, by clicking the link prefix is added to the author. Like _en/about.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Link href="/about" locale={false}&amp;gt;
  About Page (locale false)
&amp;lt;/Link&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As locale is false, by clicking the link prefix will not be added to the &lt;em&gt;about&lt;/em&gt;. Like &lt;em&gt;/about&lt;/em&gt;. It works like it normally does.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 onNavigate
&lt;/h4&gt;

&lt;p&gt;An event handler is called during client-side navigation. The handler receives an event object that includes a preventDefault() method, allowing you to cancel the navigation if needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link'

export default function Page() {
  return (
    &amp;lt;Link
      href="/dashboard"
      onNavigate={(e) =&amp;gt; {
        // Only executes during SPA navigation
        console.log('Navigating...')

        // Optionally prevent navigation
        // e.preventDefault()
      }}
    &amp;gt;
      Dashboard
    &amp;lt;/Link&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While &lt;code&gt;onClick&lt;/code&gt; and &lt;code&gt;onNavigate&lt;/code&gt; may seem similar, they serve different purposes. &lt;code&gt;onClick&lt;/code&gt; executes for all click events, while &lt;code&gt;onNavigate&lt;/code&gt; only runs during &lt;code&gt;client-side&lt;/code&gt; navigation.&lt;br&gt;
Some key differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;onClick&lt;/code&gt; executes with keyboard commands to navigate, but &lt;code&gt;onNavigate&lt;/code&gt; won't. &lt;/li&gt;
&lt;li&gt;External URLs won't trigger &lt;code&gt;onNavigate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Links with the &lt;code&gt;download&lt;/code&gt; attribute will work with &lt;code&gt;onClick&lt;/code&gt; but not &lt;code&gt;onNavigate&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  👉 Open the Linked page in a new tab
&lt;/h4&gt;

&lt;p&gt;If you want, the following page/coponent will be opened in a new tab. As like &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag does with &lt;code&gt;target='_blank'&lt;/code&gt; attributes. You can do it with &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component in Next.js in the same way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
   &amp;lt;Link href="/contactus" target='_blank'&amp;gt;
     &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md"&amp;gt;
                Go to Contact us Page
     &amp;lt;/button&amp;gt;
   &amp;lt;/Link&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use other target attributes like: &lt;code&gt;_parent&lt;/code&gt;, &lt;code&gt;_self&lt;/code&gt;, &lt;code&gt;_top&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;The &lt;code&gt;Link&lt;/code&gt; component is very useful in Next.js to navigate different pages in your web application. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>frontend</category>
      <category>nextlink</category>
    </item>
    <item>
      <title>Layout in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Thu, 08 May 2025 17:26:41 +0000</pubDate>
      <link>https://dev.to/khanrabiul/layout-in-nextjs-55dk</link>
      <guid>https://dev.to/khanrabiul/layout-in-nextjs-55dk</guid>
      <description>&lt;p&gt;&lt;code&gt;layout.tsx&lt;/code&gt; takes a &lt;code&gt;React component&lt;/code&gt; as a &lt;code&gt;children&lt;/code&gt;. There is a default &lt;code&gt;layout&lt;/code&gt; file in the &lt;code&gt;app&lt;/code&gt; directory. The file determines the main layout of &lt;code&gt;Header, Footer, and other&lt;/code&gt; general &lt;code&gt;component&lt;/code&gt;. The &lt;code&gt;layout&lt;/code&gt; file in the &lt;code&gt;app&lt;/code&gt; directory can not be removed. It means if you delete the file and run the project, the &lt;code&gt;layout&lt;/code&gt; file will be regenerated.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;layout&lt;/code&gt; file may look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/layout.tsx

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body&amp;gt;
        &amp;lt;header&amp;gt;My App Header&amp;lt;/header&amp;gt;
        &amp;lt;main&amp;gt;{children}&amp;lt;/main&amp;gt;
        &amp;lt;footer&amp;gt;My App Footer&amp;lt;/footer&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the superpower of &lt;code&gt;Next.js&lt;/code&gt;, &lt;code&gt;layout&lt;/code&gt; receives all the files named &lt;code&gt;page.tsx/jsx/...&lt;/code&gt; and creates UI for you. &lt;code&gt;Next.js&lt;/code&gt; automatically wraps all &lt;code&gt;page.tsx (or .js/.jsx/.tsx)&lt;/code&gt; files under &lt;code&gt;app/&lt;/code&gt; with the nearest &lt;code&gt;layout.tsx&lt;/code&gt; in the file tree. You don’t manually &lt;code&gt;import&lt;/code&gt; or attach &lt;code&gt;pages&lt;/code&gt; to &lt;code&gt;layouts—file-system conventions&lt;/code&gt;, do that for you.&lt;/p&gt;




&lt;h2&gt;
  
  
  Nested &lt;code&gt;layout&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In your project, you need one shared &lt;code&gt;layout&lt;/code&gt; and another for deeper. Like, for &lt;code&gt;root layout&lt;/code&gt; &lt;code&gt;app/layout.tsx&lt;/code&gt; and for nested &lt;code&gt;app/user/username/layout.tsx&lt;/code&gt;.&lt;br&gt;
The folder structure should look like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;next-practice/app/
├── globals.css
├── layout.tsx
├── page.tsx
└── user/
    ├── page.tsx
    └── username/
        ├── layout.tsx
        └── page.tsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How's it working?&lt;/p&gt;

&lt;h3&gt;
  
  
  * root layout &lt;code&gt;app/layout.tsx&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It renders all children until it finds another &lt;code&gt;layout.tsx&lt;/code&gt; file. In our case, the root &lt;code&gt;layout&lt;/code&gt; will render the &lt;code&gt;app/page.tsx&lt;/code&gt; and &lt;code&gt;user/page.tsx&lt;/code&gt; as they are the children of &lt;code&gt;layout.tsx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;As &lt;code&gt;app/user/username/layout.tsx&lt;/code&gt; contains another &lt;code&gt;layout&lt;/code&gt; file, it will stop rendering the root &lt;code&gt;layout&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;At this point, &lt;code&gt;app/user/username/layout.tsx&lt;/code&gt; will render the new layout's &lt;code&gt;UI&lt;/code&gt;, how you designed. &lt;/li&gt;
&lt;li&gt;Now &lt;code&gt;app/user/username/layout.tsx&lt;/code&gt; becomes the root layout for its nested &lt;code&gt;pages/routes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you create more nested directories and &lt;code&gt;page.tsx&lt;/code&gt; in the &lt;code&gt;username&lt;/code&gt;, they will be rendered in the &lt;code&gt;app/user/username/layout.tsx&lt;/code&gt; layout.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Keeping the &lt;code&gt;page.tsx&lt;/code&gt; in the same directory as &lt;code&gt;layout.tsx&lt;/code&gt; is a must. Otherwise, the &lt;code&gt;route segment&lt;/code&gt; for the layout will not be accessible. &lt;em&gt;Keep in mind &lt;code&gt;layout.tsx&lt;/code&gt; does not create &lt;code&gt;route&lt;/code&gt;, but &lt;code&gt;page.tsx&lt;/code&gt; does. So to make the &lt;code&gt;route&lt;/code&gt; accessible, you need the &lt;code&gt;page.tsx&lt;/code&gt; there.&lt;/em&gt; For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;next-practice/app/
├── globals.css
├── layout.tsx           
└── user/
    ├── page.tsx     
    └── username/
        ├── layout.tsx  

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you try to access &lt;code&gt;/user/username&lt;/code&gt; you will see &lt;code&gt;404 Not Found Page&lt;/code&gt;. As there is no &lt;code&gt;page.tsx&lt;/code&gt; file. To make the &lt;code&gt;route&lt;/code&gt; accessible add a &lt;code&gt;page.tsx/js/jsx/...&lt;/code&gt; file there.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>layout</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Dynamic Routes in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Sun, 04 May 2025 15:37:04 +0000</pubDate>
      <link>https://dev.to/khanrabiul/dynamic-routes-in-nextjs-4o74</link>
      <guid>https://dev.to/khanrabiul/dynamic-routes-in-nextjs-4o74</guid>
      <description>&lt;p&gt;A dynamic route lets your application handle URLs whose segments aren’t known ahead of time. In Next.js, you create a &lt;code&gt;dynamic segment&lt;/code&gt; by wrapping a folder or file name in square brackets &lt;code&gt;[]&lt;/code&gt;. The App Router then maps any matching &lt;code&gt;URL&lt;/code&gt; into that segment and passes its value as a &lt;code&gt;params&lt;/code&gt; &lt;code&gt;object&lt;/code&gt; to your page component. This approach keeps your routing flexible and your code &lt;code&gt;DRY&lt;/code&gt;, whether you’re building user profiles &lt;code&gt;/users/[username]&lt;/code&gt; or blog posts &lt;code&gt;/posts/[id]&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Dynamic Routes?
&lt;/h3&gt;

&lt;p&gt;Dynamic Routes allow you to define &lt;code&gt;URL&lt;/code&gt; patterns with placeholders instead of hard-coding every path. When a request arrives, &lt;code&gt;Next.js&lt;/code&gt; fills in those placeholders and hands you the values to render the right content. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why use them?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility: One &lt;code&gt;route&lt;/code&gt; file can handle dozens or thousands of URLs without manual setup.&lt;/li&gt;
&lt;li&gt;Scalability: Your codebase stays lean as your app grows.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Setting up Dynamic Routes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Add square brackets around the segment name in your app folder.&lt;/li&gt;
&lt;li&gt;Next.js will treat that bracketed folder (or file) as a dynamic segment
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├── layout.js
├── page.js
└── blog/
    └── [slug_Or_Any_Name]/
        └── page.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;app/blog/[slug]/page.js&lt;/code&gt; file will be rendered for the &lt;code&gt;/blog/&amp;lt;value&amp;gt;&lt;/code&gt; route.&lt;/p&gt;




&lt;h3&gt;
  
  
  Working with Route Parameters
&lt;/h3&gt;

&lt;p&gt;When you &lt;code&gt;export&lt;/code&gt; an &lt;code&gt;async&lt;/code&gt; page component inside a dynamic folder, &lt;code&gt;Next.js&lt;/code&gt; injects a &lt;code&gt;params object&lt;/code&gt; containing your segment value(s):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/blog/[slug]/page.tsx
interface Params { slug: string }

const BlogPost = async ({ params }: { params: Params }) =&amp;gt; {
  // params.slug holds the URL value, e.g. "my-first-post"
  return &amp;lt;h1&amp;gt;Post: {params.slug}&amp;lt;/h1&amp;gt;
}

export default BlogPost

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The page component must be async because Next.js may fetch data before rendering. &lt;/li&gt;
&lt;li&gt;You can destructure params directly in the function signature.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Catch-All segments
&lt;/h2&gt;

&lt;p&gt;You can create an infinite sub-route under a route.&lt;br&gt;
In general &lt;code&gt;catch-all-segment&lt;/code&gt; takes a value. But &lt;code&gt;catch-all-segment&lt;/code&gt; can hold all nested routes' value as an array of strings.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create &lt;code&gt;catch-all segment&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Like dynamic route, make the directory into &lt;code&gt;[]&lt;/code&gt; add &lt;code&gt;...&lt;/code&gt; before the directory name. &lt;code&gt;[...slug]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/app/[...path]/page.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Get &lt;code&gt;params&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Product = async ({params} : {params : path: string[]) =&amp;gt; {
const {path} = await param;
return (
&amp;lt;&amp;gt;
&amp;lt;h1&amp;gt; Return you page or component &amp;lt;/h1&amp;gt;
)
}
export default Product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now you can see your component at this &lt;code&gt;URL&lt;/code&gt; endpoint.&lt;/p&gt;
&lt;h2&gt;
  
  
  Optional &lt;code&gt;catch-all segment&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;If you want to match both the base route and deeper paths with one file, wrap the catch-all in double brackets. This way, no error occurs when no segments are provided. You can make the &lt;code&gt;catch-all segments&lt;/code&gt; optional by adding the parameter in double square brackets: &lt;code&gt;[[...slug]]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
└── docs/
    ├── page.tsx              # handles the base /docs route
    └── [[...slug]]/          # optional catch-all
        └── page.tsx          # handles /docs/* at any depth


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deep dive into the optional &lt;code&gt;catch-all segment&lt;/code&gt;: In &lt;code&gt;Next.js&lt;/code&gt;, showing how to serve &lt;code&gt;/docs&lt;/code&gt; with its own page and route all deeper paths &lt;code&gt;/docs/post1, /docs/post2, /docs/post1/comments/2, etc&lt;/code&gt;. to a single catch-all handler—without triggering a 404 for &lt;code&gt;unknown slugs&lt;/code&gt;. You’ll see folder setup, how &lt;code&gt;Next.js&lt;/code&gt; maps &lt;code&gt;URLs&lt;/code&gt; to &lt;code&gt;params&lt;/code&gt;, and how to render your &lt;code&gt;page&lt;/code&gt; component unconditionally for any nested route.&lt;br&gt;
&lt;code&gt;Optional catch-all segments&lt;/code&gt; use [[...slug]] in your folder name. This matches both the base path &lt;code&gt;/docs&lt;/code&gt; with params.&lt;code&gt;slug === undefined&lt;/code&gt;and any depth &lt;code&gt;/docs/*&lt;/code&gt; with params&lt;code&gt;.slug&lt;/code&gt; as an &lt;code&gt;array&lt;/code&gt; of &lt;code&gt;strings&lt;/code&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  Folder Structure
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
└── docs/
    ├── page.tsx              # handles the base /docs route
    └── [[...slug]]/          # optional catch-all
        └── page.tsx          # handles /docs/* at any depth

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Visiting &lt;code&gt;/docs&lt;/code&gt; → renders &lt;code&gt;app/docs/page.tsx&lt;/code&gt; with no params&lt;/li&gt;
&lt;li&gt;Visiting &lt;code&gt;/docs/post1&lt;/code&gt; → renders &lt;code&gt;app/docs/[[...slug]]/page.tsx&lt;/code&gt; with &lt;code&gt;params.slug === ['post1']&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Visiting &lt;code&gt;/docs/post1/comments/2&lt;/code&gt; → same catch-all page with &lt;code&gt;params.slug === ['post1','comments','2']&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NB: We never call notFound() when doc is missing; instead, we show fallback content&lt;br&gt;
Handling params&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/docs/[[...slug]]/page.tsx

interface Params {
  // slug may be undefined (for /docs) or an array of strings
  slug?: string[];
}

const DocsCatchAll = async ({ params }: { params: Params }) =&amp;gt; {
  // Normalize to an array so you can always iterate or destructure safely
  const parts = params.slug ?? [];  
  // e.g. [] for /docs, ['post1'] for /docs/post1, etc.

  // Example destructure:
  const [post, section, id] = parts;

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Catch-all Docs Page&amp;lt;/h1&amp;gt;
      {parts.length === 0 &amp;amp;&amp;amp; &amp;lt;p&amp;gt;This is the main docs home.&amp;lt;/p&amp;gt;}
      {parts.length === 1 &amp;amp;&amp;amp; &amp;lt;p&amp;gt;Showing doc: {post}&amp;lt;/p&amp;gt;}
      {parts.length === 2 &amp;amp;&amp;amp; &amp;lt;p&amp;gt;Inside section “{section}” of {post}&amp;lt;/p&amp;gt;}
      {parts.length &amp;gt;= 3 &amp;amp;&amp;amp; (
        &amp;lt;p&amp;gt;
          Deep path: {post} / {section} / {id}… ({parts.join(' / ')})
        &amp;lt;/p&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
};

export default DocsCatchAll;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>dynamicroutes</category>
      <category>frontend</category>
    </item>
    <item>
      <title>useRouter in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Wed, 30 Apr 2025 06:01:45 +0000</pubDate>
      <link>https://dev.to/khanrabiul/userouter-in-nextjs-4p7h</link>
      <guid>https://dev.to/khanrabiul/userouter-in-nextjs-4p7h</guid>
      <description>&lt;p&gt;The &lt;code&gt;useRouter&lt;/code&gt; is a hook in Next.js providing programmatic navigation and access to the current route's data. Calling the hook returns an object. From the object you can get access to &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current path name (pathname)&lt;/li&gt;
&lt;li&gt;query parameter (query)&lt;/li&gt;
&lt;li&gt;with push, replace, and other methods, able to navigate between pages/components&lt;/li&gt;
&lt;li&gt;can control browser history with back, reload, and other methods.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  👉 How to use &lt;code&gt;useRouter&lt;/code&gt; hook
&lt;/h3&gt;

&lt;p&gt;First, import from the correct packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRouter } from 'next/navigation'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;NB:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;next/router&lt;/em&gt; is deprecated in Next.js 15.&lt;br&gt;
Since &lt;code&gt;useRouter&lt;/code&gt; is a client-side hook, you have to use &lt;code&gt;"use client"&lt;/code&gt; at the top of the file.&lt;/p&gt;



&lt;p&gt;&lt;code&gt;useRouter&lt;/code&gt; hook returns an object of &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;push&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;back&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;forward&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;refresh&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;replace&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prefetch&lt;/code&gt; and &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hmrRefresh&lt;/code&gt; methods
Let's describe one by one.&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  👉 &lt;code&gt;push&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It is used to navigate new routes programmatically. It adds a new browser history to the stack. Its syntax is &lt;code&gt;router.push(href, options?)&lt;/code&gt;. Providing an option is not mandatory. &lt;br&gt;
&lt;strong&gt;&lt;em&gt;NB: To know more about &lt;code&gt;optoins&lt;/code&gt; read the article. Link props are similar to options&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/khanrabiul/link-and-its-props-in-nextjs-5g0h-temp-slug-9835681?preview=b6a7ee9da21622b3cdbcf70087c07e85f65bad04119d9e5679ed5ac391f21b96e01349bac49a31d2dae5a6deb680c4de375309da5f354a08399f9f35"&gt;Know more about option or &lt;code&gt;Link&lt;/code&gt; props&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use client";
import { useRouter } from "next/navigation";
const AboutPage = () =&amp;gt; {
  const router = useRouter();
  const aboutRouteHandler = () =&amp;gt; {
    router.push('/about');
  }
  const contactRouteHandler = () =&amp;gt; {
    router.push('/contactus', {scroll: false});
  }
  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;div&amp;gt;
        {/* Without option */}
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" onClick={aboutRouteHandler}&amp;gt;
          Go to About Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        {/* With option */}
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" 
        onClick={contactRouteHandler}&amp;gt;
          Go to Contact us Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default AboutPage;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users can navigate new page, keeping the option to go back to the previous page.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 &lt;code&gt;replace&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It updates the current history entry and removes the previous entry. Syntax: &lt;code&gt;router.replace(href, options?)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useRouter } from "next/navigation";
const AboutPage = () =&amp;gt; {
  const router = useRouter();
  const aboutRouteHandler = () =&amp;gt; {
    router.replace('/about');
  }
  const contactRouteHandler = () =&amp;gt; {
    router.replace('/contactus', {scroll: false});
  }
  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;div&amp;gt;
        {/* Without option */}
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" onClick={aboutRouteHandler}&amp;gt;
          Go to About Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        {/* With option */}
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" 
        onClick={contactRouteHandler}&amp;gt;
          Go to Contact us Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default AboutPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For using &lt;code&gt;replace&lt;/code&gt; method, users are not able to go back to the previous page.&lt;/p&gt;

&lt;p&gt;--Where to use:--&lt;br&gt;
After login, form submission users will be redirected to another page. And going back to the login, form page does not make sense.&lt;/p&gt;


&lt;h4&gt;
  
  
  👉 &lt;code&gt;refresh&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;refresh&lt;/code&gt; the current page without affecting the browsing history. It is used to update and reflect the latest state. It re-fetched data and the server component. Syntax: &lt;code&gt;router.refresh()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useRouter } from "next/navigation";
const AboutPage = () =&amp;gt; {
  const router = useRouter();

  const aboutRouteHandler = () =&amp;gt; {
    router.refresh();
  }
  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;div&amp;gt;
        {/* Without option */}
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" onClick={aboutRouteHandler}&amp;gt;
          Go to About Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt; 
    &amp;lt;/div&amp;gt;
  );
};
export default AboutPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  👉 &lt;code&gt;prefetch&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;prefetch&lt;/code&gt; cached JS, data, and segment for the specific routes. So that, for the next click, the page can be loaded immediately. Syntax: &lt;code&gt;router.prefetch(href)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';

export default function AboutPage() {
  const router = useRouter();

  useEffect(() =&amp;gt; {
    // যখন AboutPage কম্পোনেন্ট মাউন্ট হবে তখনই প্রিফেচ
    router.prefetch('/contactus');
    router.prefetch('/help');
  }, [router]);

  const handleGo = (path) =&amp;gt; {
    router.push(path);
  };

  return (
    &amp;lt;div className="space-y-4"&amp;gt;
      &amp;lt;button
        className="px-3 py-2 bg-green-600 text-white rounded-md"
        onClick={() =&amp;gt; handleGo('/contactus')}
      &amp;gt;
        Go to Contact Us
      &amp;lt;/button&amp;gt;
      &amp;lt;button
        className="px-3 py-2 bg-indigo-600 text-white rounded-md"
        onClick={() =&amp;gt; handleGo('/help')}
      &amp;gt;
        Get Help
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those pages will be pre-loaded when using &lt;code&gt;useEffect()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;_&lt;em&gt;Or we can combine &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;prefetch&lt;/code&gt; altogether&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';
import { useRouter } from 'next/navigation';

export default function AboutPage() {
  const router = useRouter();

  const handleMouseEnter = () =&amp;gt; {
    router.prefetch('/contactus');   // Contactus
  };

  const handleClick = () =&amp;gt; {
    router.push('/contactus');       /
  };

  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;button
        className="px-3 py-2 bg-blue-600 text-white rounded-md"
        onMouseEnter={handleMouseEnter}
        onClick={handleClick}
      &amp;gt;
        Go to Contact Us
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When mouse enters the button the component get loaded in background. For &lt;code&gt;push&lt;/code&gt; method user redirected to the page immediately.&lt;/p&gt;




&lt;h4&gt;
  
  
  👉 &lt;code&gt;back&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;back&lt;/code&gt; method allows users to go back a step in history.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useRouter } from "next/navigation";
const AboutPage = () =&amp;gt; {
  const router = useRouter();

  const returnPageHandler = () =&amp;gt; {
    router.back();
  }
  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" onClick={returnPageHandler}&amp;gt;
          Back to Previous Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt; 
    &amp;lt;/div&amp;gt;
  );
};
export default AboutPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  👉 &lt;code&gt;forward&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;forward&lt;/code&gt; works the same way as the &lt;code&gt;back&lt;/code&gt; method does. But goes one step forward from history.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useRouter } from "next/navigation";
const AboutPage = () =&amp;gt; {
  const router = useRouter();

  const nextPageHandler = () =&amp;gt; {
    router.forward();
  }
  return (
    &amp;lt;div className="space-y-8"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;button className="px-3 py-2 bg-blue-600 text-white rounded-md" onClick={nextPageHandler}&amp;gt;
          Go to Next Page
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt; 
    &amp;lt;/div&amp;gt;
  );
};
export default AboutPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  👉 &lt;code&gt;hmrRefresh()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It works only in development mode. Without reloading the page fully, it refreshes the page's data.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>frontend</category>
      <category>userouter</category>
    </item>
    <item>
      <title>Routes Group - Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Tue, 22 Apr 2025 09:08:10 +0000</pubDate>
      <link>https://dev.to/khanrabiul/routes-group-nextjs-4pfb</link>
      <guid>https://dev.to/khanrabiul/routes-group-nextjs-4pfb</guid>
      <description>&lt;p&gt;We know that creating any folder in &lt;code&gt;App Router&lt;/code&gt; creates a route. But if you want to create nested route without breaking &lt;code&gt;URL&lt;/code&gt;. You can use &lt;code&gt;routes group&lt;/code&gt;.&lt;br&gt;
&lt;em&gt;You want to make routes like: &lt;a href="http://localhost:3000/signout" rel="noopener noreferrer"&gt;http://localhost:3000/signout&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
and &lt;em&gt;&lt;a href="http://localhost:3000/signin" rel="noopener noreferrer"&gt;http://localhost:3000/signin&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
First, take a look at the problem, if you do in general.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├── auth/
│   ├── login/
│   │   └── page.js
|   ├── logout/
│   │   └── page.js
└── layout.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now try to access &lt;em&gt;&lt;a href="http://localhost:3000/signout" rel="noopener noreferrer"&gt;http://localhost:3000/signout&lt;/a&gt;&lt;/em&gt; _&lt;br&gt;
and &lt;em&gt;&lt;a href="http://localhost:3000/signin" rel="noopener noreferrer"&gt;http://localhost:3000/signin&lt;/a&gt;.&lt;/em&gt; You are redirected to &lt;em&gt;404 Not Found Page&lt;/em&gt;. &lt;br&gt;
What happens? &lt;br&gt;
&lt;code&gt;app&lt;/code&gt; is the root route. Then you add another directory named &lt;code&gt;auth&lt;/code&gt;. Into &lt;code&gt;auth&lt;/code&gt; login and logout belong. So the &lt;code&gt;URL&lt;/code&gt; becomes  &lt;em&gt;&lt;a href="http://localhost:3000/auth/signout" rel="noopener noreferrer"&gt;http://localhost:3000/auth/signout&lt;/a&gt;&lt;/em&gt; _&lt;br&gt;
and &lt;em&gt;&lt;a href="http://localhost:3000/auth/signin" rel="noopener noreferrer"&gt;http://localhost:3000/auth/signin&lt;/a&gt;.&lt;/em&gt; &lt;br&gt;
Go to those links you will see your signing or signout page.&lt;/p&gt;
&lt;h2&gt;
  
  
  But you don't want to add &lt;code&gt;auth&lt;/code&gt; to your routes. How can you achieve it?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;routes group&lt;/code&gt;: The folder you don't want to add as a route, keep the folder name in &lt;code&gt;parentheses()&lt;/code&gt;. You have done it! It is so simple in Next.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├── (auth)/
│   ├── login/
│   │   └── page.js
|   ├── logout/
│   │   └── page.js
└── layout.js

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to those links: &lt;a href="http://localhost:3000/signout_" rel="noopener noreferrer"&gt;http://localhost:3000/signout_&lt;/a&gt;&lt;br&gt;
And &lt;em&gt;&lt;a href="http://localhost:3000/signin" rel="noopener noreferrer"&gt;http://localhost:3000/signin&lt;/a&gt;&lt;/em&gt;, you will find your pages. &lt;/p&gt;




&lt;p&gt;By using &lt;code&gt;routes group&lt;/code&gt;, you can keep your route structure clean, modular, and layout focused. &lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>routesgroup</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to create page in Next.js</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Sun, 20 Apr 2025 15:40:10 +0000</pubDate>
      <link>https://dev.to/khanrabiul/how-to-create-page-in-nextjs-fa</link>
      <guid>https://dev.to/khanrabiul/how-to-create-page-in-nextjs-fa</guid>
      <description>&lt;h2&gt;
  
  
  page.tsx
&lt;/h2&gt;

&lt;p&gt;File-based routing is introduced in Next.js from v13. That means the file's name is the route name.&lt;br&gt;
If we create a page.tsx into the app directory, the page.tsx will create the default route.This is known as the home route. If you visit &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/ &lt;/a&gt; you can see the Home component there.&lt;/p&gt;

&lt;p&gt;File structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;└── app/
    └── page.tsx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again if we create any directory under app directory,this will create a new route. The name of the route is the of the file itself. Like we want to create a new route about. User can see the about component or page if he/she navigate to &lt;a href="http://localhost:3000/about" rel="noopener noreferrer"&gt;http://localhost:3000/about &lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;└── app/
    ├── about/
    │   └── page.tsx
    └── page.tsx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const AboutPage: React.FC = () =&amp;gt; {
  return (
    &amp;lt;div className="container mx-auto p-8"&amp;gt;
      &amp;lt;h1 className="text-4xl font-bold text-gray-800 mb-6"&amp;gt;About Us&amp;lt;/h1&amp;gt;
      &amp;lt;div className="bg-white shadow-md rounded-lg p-6"&amp;gt;
        &amp;lt;p className="text-gray-700 leading-relaxed mb-4"&amp;gt;
          Welcome to our website! We are a team of passionate individuals dedicated to creating amazing things.
        &amp;lt;/p&amp;gt;
        &amp;lt;p className="text-gray-700 leading-relaxed mb-4"&amp;gt;
          Our mission is to provide high-quality services and products that meet the needs of our customers.
        &amp;lt;/p&amp;gt;
        &amp;lt;p className="text-gray-700 leading-relaxed"&amp;gt;
          We believe in innovation, collaboration, and continuous improvement.
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default AboutPage;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now user see the AboutPage component or page if he/she navigate to &lt;a href="http://localhost:3000/about" rel="noopener noreferrer"&gt;http://localhost:3000/about&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  NB: Naming Convention: Use all lowercase letters for directory names to follow best practices.
&lt;/h3&gt;

&lt;p&gt;To create a route we need a folder. The folder name is the route. Inside that folder, add a special file named page.tsx, page.jsx, or page.js. This file contains the component that will render when the route is accessed. &lt;br&gt;
Now we are able to create any route for level one. But what about &lt;a href="http://localhost:3000/products/mobile/samsung" rel="noopener noreferrer"&gt;http://localhost:3000/products/mobile/samsung&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Nested Routes
&lt;/h2&gt;

&lt;p&gt;Imagine the situation, where the user can navigate to the home page, and clicking on a product will navigate to the products page. Clicking on a product from the products page, the user will navigate to the specific product (mobile) route. Further, if the user wants to see product(mobile) details user will be navigated to another route(samsung). How can we do this?&lt;br&gt;
It is very simple in Next.js. You should think simply. &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 01: We know to create a route we need a directory. The directory name must be matched with the route name.
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Step 02: Into &lt;code&gt;app&lt;/code&gt; directory there is a &lt;code&gt;page.tsx&lt;/code&gt; file that will create the home route. &lt;a href="https://dev.tohttp//:localhost:3000/"&gt;http//:localhost:3000/&lt;/a&gt;
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Step 03: Nested Routes
&lt;/h3&gt;

&lt;p&gt;For every nested routes, we also need a nested directory. In our case, our route is &lt;a href="//.../products/mobile/samsung"&gt;.../products/mobile/samsung&lt;/a&gt;. This means need a directory in &lt;code&gt;app&lt;/code&gt; directory named &lt;code&gt;products&lt;/code&gt;. Then create another directory in &lt;code&gt;products&lt;/code&gt; directory named &lt;code&gt;mobile&lt;/code&gt;. In the same way, create another directory named &lt;code&gt;samsung&lt;/code&gt; into &lt;code&gt;mobile&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;└── app/
    ├── about/
    │   └── page.tsx
    ├── page.tsx
    └── products/
        └── mobile/
            └── samsung/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just created the routes &lt;a href="http://localhost:3000/products/mobile/samsung" rel="noopener noreferrer"&gt;http://localhost:3000/products/mobile/samsung&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 04: page.tsx
&lt;/h3&gt;

&lt;p&gt;However, the user can not access the routes. If any user tries to access the routes he/she will be directed to 404 | Not Found page. To make it publically accessible we need a special file &lt;code&gt;page.tsx&lt;/code&gt; for every nested route. Into the &lt;code&gt;page.tsx&lt;/code&gt; file you can render your desired component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;└── app/
    ├── about/
    │   └── page.tsx
    ├── page.tsx
    └── products/
        ├── mobile/
        │   ├── page.tsx
        │   └── samsung/
        │       └── page.tsx
        └── page.tsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now users can get access to the routes. &lt;br&gt;
If the user navigates &lt;a href="http://localhost:3000/products" rel="noopener noreferrer"&gt;http://localhost:3000/products&lt;/a&gt; user can see &lt;code&gt;products&lt;/code&gt; page. &lt;br&gt;
By navigating &lt;a href="http://localhost:3000/products/mobile" rel="noopener noreferrer"&gt;http://localhost:3000/products/mobile&lt;/a&gt; users have access to this routes. Finally use have access for &lt;a href="http://localhost:3000/products/mobile/samsung" rel="noopener noreferrer"&gt;http://localhost:3000/products/mobile/samsung&lt;/a&gt; routes.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>programming</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Tailwind CSS V4 Dark Mode</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Thu, 03 Apr 2025 18:44:44 +0000</pubDate>
      <link>https://dev.to/khanrabiul/tailwind-css-v4-dark-mode-3kbl</link>
      <guid>https://dev.to/khanrabiul/tailwind-css-v4-dark-mode-3kbl</guid>
      <description>&lt;h2&gt;
  
  
  How to implement theme toggler in tailwind CSS v4 in React project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Theme handler
&lt;/h3&gt;

&lt;p&gt;First, we need a button or a component that will toggle dark and light mode.&lt;br&gt;
Into the component, we need &lt;code&gt;useState&lt;/code&gt; to hold the context's current value.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create the Theme Controller component
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Button.jsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const DarkModeToggler = () =&amp;gt; {
return (
&amp;lt;&amp;gt;
&amp;lt;button&amp;gt;
{darkMode ? "Dark" : "Light" }
&amp;lt;/button&amp;gt;
)
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use in CSS file. The file could be &lt;code&gt;index.css&lt;/code&gt; or &lt;code&gt;global.css&lt;/code&gt; or something else.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "tailwindcss";
@custom-variant dark (&amp;amp;:where(.dark, .dark *));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create Context
&lt;/h3&gt;

&lt;p&gt;Now create a context. It should look like this &lt;code&gt;src/context/ThemeContext.jsx&lt;/code&gt;. Into the &lt;code&gt;ThemeContext.jsx&lt;/code&gt; component we will implement the react context's logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {createContext, useEffect, useState } from "react";

const ThemeContext = createContext('light');

const ThemeProvider = ({children}) =&amp;gt; {
const [darkMode, setDarkMode] = useState(
localStorage.getItem("theme") === "dark"
)

return(
&amp;lt;ThemeContext.Provider value={{darkMode,setDarkMode}}&amp;gt;
{children}
&amp;lt;/ThemeContext.Provider&amp;gt;
)

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can use hard-coded &lt;code&gt;useState&lt;/code&gt;logic. Like &lt;code&gt;const [darkMode, setDarkMode] = useState('light')&lt;/code&gt;. This will also work. But when a user refreshes the page the &lt;code&gt;useState&lt;/code&gt; value will be re-seted. To prevent this issue we used localStorage, which is the current value for &lt;code&gt;darkMode&lt;/code&gt;.To know when to use dark mode and when to use light mode, we need to use &lt;code&gt;useEffect&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
if(darkMode) {
document.documentElement.classList.add("dark");
localStorage.setItem("theme", "dark");
} else { 
  document.documentElement.classList.remove("dark");
loacalStorage.setItem("theme", "light");
}
}, 
[darkMode]) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createContext, useContext, useEffect, useState } from "react";

const ThemeContext = createContext();

export const ThemeProvider = ({ children }) =&amp;gt; { 
  const [darkMode, setDarkMode] = useState(
    localStorage.getItem("theme") === "dark"
  );

  useEffect(() =&amp;gt; {
    if (darkMode) {
      document.documentElement.classList.add("dark");
      localStorage.setItem("theme", "dark");
    } else { 
      document.documentElement.classList.remove("dark");
      localStorage.setItem("theme", "light");
    }
  }, [darkMode]);

  return (
    &amp;lt;ThemeContext.Provider value={{ darkMode, setDarkMode }}&amp;gt;
      {children}
    &amp;lt;/ThemeContext.Provider&amp;gt;
  );
};

export const useDarkMode = () =&amp;gt; useContext(ThemeContext);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Export &lt;code&gt;ThemeContext&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const useDarkMode = () =&amp;gt; useContext(ThemeContext)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  NB: Don't forget to export the component &lt;code&gt;export const ThemeProvider = () =&amp;gt; {...}&lt;/code&gt;
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Here is the final code for &lt;code&gt;ThemeContext.jsx&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createContext, useContext, useState, useEffect } from "react";

const ThemeContext = createContext("light");

export const ThemeProvider = ({ children }) =&amp;gt; {
  const [darkMode, setDarkMode] = useState(
    localStorage.getItem("theme") === "dark"
  );

  useEffect(() =&amp;gt; {
    if (darkMode) {
      document.documentElement.classList.add("dark");
      localStorage.setItem("theme", "dark");
    } else {
      document.documentElement.classList.remove("dark");
      localStorage.setItem("theme", "light");
    }
  }, [darkMode]);

  return (
    &amp;lt;ThemeContext.Provider value={{ darkMode, setDarkMode }}&amp;gt;
      {children}
    &amp;lt;/ThemeContext.Provider&amp;gt;
  );
};

export const useDarkMode = () =&amp;gt; useContext(ThemeContext);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to use controlling them.&lt;br&gt;
To implement we have to go to the root component.&lt;code&gt;main.jsx&lt;/code&gt; and wrap it with &lt;code&gt;&amp;lt;ThemeProvider&amp;gt; ...&amp;lt;/ThemeProvider&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import ThemeProvider from "./context/ThemeContext.jsx";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")).render(
  &amp;lt;ThemeProvider&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/ThemeProvider&amp;gt;
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change the state in the toggler component(&lt;code&gt;DarkModeToggler.jsx&lt;/code&gt;) and import &lt;code&gt;state&lt;/code&gt; from &lt;code&gt;ThemeContext&lt;/code&gt;. To toggle them we need an &lt;code&gt;onClick&lt;/code&gt; and a &lt;code&gt;handlerfunction&lt;/code&gt; The component should look like this.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useContext } from "react";
import { ThemeContext } from "../context/ThemeContext";

const DarkModeToggler = () =&amp;gt; {
  const { darkMode, setDarkMode } = useContext(ThemeContext);

  return (
    &amp;lt;button
      onClick={() =&amp;gt; setDarkMode((prev) =&amp;gt; !prev)}
      className="p-2 border rounded"
    &amp;gt;
      {darkMode ? "Light Mode" : "Dark Mode"}
    &amp;lt;/button&amp;gt;
  );
};

export default DarkModeToggler;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to use dark and light mode in our application. &lt;/p&gt;

&lt;p&gt;Here is a simple example of how to use the theme.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useDarkMode } from "../context/ThemeContext";

const Card = () =&amp;gt; {
  const { darkMode } = useDarkMode();

  return (
    &amp;lt;div className="p-5 rounded-lg shadow-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100"&amp;gt;
      &amp;lt;h2 className="text-xl font-bold"&amp;gt;Dark Mode Card&amp;lt;/h2&amp;gt;
      &amp;lt;p className="mt-2"&amp;gt;This card changes theme based on the mode.&amp;lt;/p&amp;gt;
      &amp;lt;button className="mt-4 px-4 py-2 bg-blue-500 dark:bg-blue-700 text-white rounded-lg"&amp;gt;
        Click Me
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Card;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>tailwindcss</category>
      <category>darkmode</category>
      <category>themes</category>
    </item>
    <item>
      <title>NavLInk</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Sun, 15 Dec 2024 16:07:48 +0000</pubDate>
      <link>https://dev.to/khanrabiul/navlink-3215</link>
      <guid>https://dev.to/khanrabiul/navlink-3215</guid>
      <description>&lt;p&gt;NavLink, Link-এর মতই কাজ করে। তবে এটি Navigation Link তৈরিতে ব্যবহৃত হয়। NavLink active state handle করতে পারে। কোন Link-টি active আছে তাতে নির্দিষ্ট style যুক্ত করা যায়।&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {NavLink} from "react-router-dom";
&amp;lt;NavLink to="contact"
calssName={function for dynamic style}
&amp;lt;NavLink&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;লক্ষণীয়ঃ className: A function (with isActive as an argument) যা active state অনুযায়ী class যুক্ত করে।&lt;/p&gt;

</description>
      <category>reactrouter</category>
      <category>reactrouting</category>
      <category>reactnavlink</category>
      <category>reactlinkactive</category>
    </item>
    <item>
      <title>To nest or not to nest</title>
      <dc:creator>Khan Rabiul </dc:creator>
      <pubDate>Tue, 10 Dec 2024 16:15:26 +0000</pubDate>
      <link>https://dev.to/khanrabiul/to-nest-or-not-to-nest-2m4</link>
      <guid>https://dev.to/khanrabiul/to-nest-or-not-to-nest-2m4</guid>
      <description>&lt;h2&gt;
  
  
  কখন Route nest করতে হবে কখন করতে হবে না
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Nested Routes ব্যবহার
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Parent-Child Relationship আছে:&lt;br&gt;
যদি একটি parent component এর সাথে child component এর সরাসরি সম্পর্ক থাকে, তাহলে Nested Routes ব্যবহার করুন।&lt;br&gt;
উদাহরণ: Dashboard → Settings, Profile, Notifications।&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shared Layout বা Component:&lt;br&gt;
Parent এবং তার child routes যদি একটি shared layout (যেমন Navigation Bar, Sidebar) ব্যবহার করে, Nested Routes আদর্শ।&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Route path="dashboard" element={&amp;lt;Dashboard /&amp;gt;}&amp;gt;
  &amp;lt;Route path="settings" element={&amp;lt;Settings /&amp;gt;} /&amp;gt;
  &amp;lt;Route path="profile" element={&amp;lt;Profile /&amp;gt;} /&amp;gt;
&amp;lt;/Route&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Dynamic Routes:&lt;/li&gt;
&lt;li&gt;Parent route এর উপর ভিত্তি করে child routes তৈরির প্রয়োজন হলে Nested Routes সাহায্য করে।&lt;/li&gt;
&lt;li&gt;উদাহরণ: /products/:id এর অধীনে /products/:id/details এবং /products/:id/reviews।&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Nested Routes কখন ব্যবহার না করা?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Independent Routes:&lt;br&gt;
যদি routes গুলো parent route-এর উপর নির্ভরশীল না হয় এবং আলাদা component বা layout render করে, তাহলে Nested Routes ব্যবহার করবেন না। উদাহরণ: Home, About, Blog, Contact একে অপরের সাথে সম্পর্কিত নয়।&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Overhead কমাতে:&lt;br&gt;
Nested Routes ব্যবহারে অতিরিক্ত structure তৈরি হতে পারে। যদি খুব বেশি nesting না লাগে, তবে আলাদা আলাদা route রাখা ভালো।&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SEO এবং Performance:&lt;br&gt;
খুব বেশি nesting করলে routes জটিল হয়ে যায়। এটি SEO বা application performance-এ প্রভাব ফেলতে পারে।&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;নিজেকে সহজ এ প্রশ্নটি করুন:&lt;br&gt;
Component গুলোর মধ্যে যুক্তিসংগত Parent-Child সম্পর্ক আছে কি?&lt;br&gt;
হ্যাঁ → Nested Routes।&lt;br&gt;
না → Separate Routes।&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactrouter</category>
      <category>tonestnottonest</category>
      <category>reactpath</category>
    </item>
  </channel>
</rss>
