In the Domiex - Next JS Admin & Dashboard Template, you can dynamically update page titles based on the active route using
usePathname()
and useEffect()
. This method ensures that each page
has a unique title, improving both user experience and SEO performance.
To change other meta tags, modify the src/app/layout.jsx file accordingly.
import ClientProviders from '@src/components/common/ClientProviders'; import { Metadata } from 'next'; export function generateViewport() { return { width: 'device-width', initialScale: 1, userScalable: 'no', }; } export async function generateMetadata() { return { title: 'Domiex - Next TS Premium Admin & Dashboard Template', description: 'Domiex is a powerful and responsive admin dashboard template supporting 21 frameworks', keywords: [ 'admin dashboard template', ], openGraph: { title: 'Domiex - Next TS Premium Admin & Dashboard Template', }, } }; export default function RootLayout({ children }) { return ( <html lang="en"> <body>
{children} </body> </html> ); }
The first is to define the available routes with their respective titles. These routes will be used to dynamically update the page title based on the active URL.
DynamicTitle.js
file.export const routes = [ { path: '/dashboard', title: 'Dashboard' }, { path: '/apps-ecommerce/shop-cart', title: 'Shop Cart' }, { path: '/apps-ecommerce/wishlist', title: 'Wishlist' }, { path: '/new-page', title: 'New Page' }, // Add new page dynamically ];
Now, we will use usePathname()
to fetch the current URL and match it with the defined routes.
When a match is found, we update the document.title dynamically.
'use client'; import { useEffect } from 'react'; import { usePathname } from 'next/navigation'; import { routes } from '@src/components/common/DynamicTitle'; export default function LayoutWrapper() { const pathname = usePathname(); const route = routes.find((r) => r.path === pathname); useEffect(() => { document.title = route ? `${route.title} | Domiex - Premium Versatile Admin & Dashboard Template` : 'Domiex - Premium Versatile Admin & Dashboard Template'; }, [route]); return null; }
To apply dynamic titles across all pages, include the DynamicTitle component inside your main layout file.
import LayoutWrapper from '@src/components/layout/LayoutWrapper'; export default function Layout({ children }) { return
{children} ; }
<title>
tag inside the <head>
section.Be the first to know about new updates and exclusive discounts. No spam, just great offers!
How about
With over 7 years of experienced team, we specialize in delivering custom projects for startups, blue-chip companies, and government agencies. We have successfully completed over 250+ projects, providing tailored solutions that meet the unique needs of each client.
Hire Us© Domiex Created & Crafted by SRBThemes.