fair-rose
fair-rose5mo ago

How can i use customDocumenttitle handler

This is my App.tsx file i want to use custom DocumentTitleHandler
2 Replies
kapa.ai
kapa.ai5mo ago
Hi @jakshire01. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You can use the DocumentTitleHandler component in your App.tsx file to generate custom document titles. This component generates the document title for the current page based on predefined rules, but it also allows you to customize the title generation process by providing a custom handler function. Here's how you can use it:
import { DocumentTitleHandler } from "@refinedev/react-router-v6"; // or "@refinedev/next-router" based on your router

const customTitleHandler = ({ resource, action, params }) => {
let title = "Custom default"; // Default title

if (resource && action) {
title = `${resource} ${action} ${params.id}`;
}

return title;
};

const App = () => {
return (
<BrowserRouter>
<Refine
/* ... */
>
{/* ... */}
<DocumentTitleHandler handler={customTitleHandler} />
</Refine>
</BrowserRouter>
);
};
import { DocumentTitleHandler } from "@refinedev/react-router-v6"; // or "@refinedev/next-router" based on your router

const customTitleHandler = ({ resource, action, params }) => {
let title = "Custom default"; // Default title

if (resource && action) {
title = `${resource} ${action} ${params.id}`;
}

return title;
};

const App = () => {
return (
<BrowserRouter>
<Refine
/* ... */
>
{/* ... */}
<DocumentTitleHandler handler={customTitleHandler} />
</Refine>
</BrowserRouter>
);
};
In the above code, customTitleHandler is a function that generates a custom title based on the resource, action, and params properties. You can modify this function to suit your needs. For more information, you can refer to the refine documentation (https://refine.dev/docs/routing/integrations/next-js#documenttitlehandler). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@418995770205929473> kapa.ai is still learning and improving, please let us know how it did by reacting below