I have 2 domains in my React project that works like, "develop.something.com" and "develop.somethingnew.com". Currently both the domains taking the index.html file's title. But, now I want to set the separate individual titles for both the domains via the array methods or via the other methods when they are appeared on the UI. How should I go about implementing this?
Based on window.location object (which has the host name details) you can set the title
function buildTitle(href) {
const titles = {
"develop.something.com": "Some title",
"develop.somethingnew.com": "New Title",
};
const key = Object.keys(titles).find((t) => href.includes(t));
return key ? titles[key] : "Default title";
}
function updateTtile(title) {
window.document.title = title;
}
// In the component
updateTitle(buildTitle(window.location.href));