I want to make a Dynamic page title on ReactJS. I try a lot of things , but didn't succeed. I make an array with data:
let pageTitles = [
{key:"/Home", title:"Welcome Home"},
{key:"/SecondPage", title:"Shop"},
{key:"/ThirdPage", title:"ContactUs"},
];
In html is only <title></title> , I use let pathname = window.location.pathname; If it return "/Home" or "/ThirdPage" to set a new title dynamically.
I've tried something like that:
for (var i = 0, len = pageTitles.length; i < len; i++) {
if (pageTitles[i].key === pathname) {
var hhh = pageTitles[i].text;
}
}
document.title = hhh
But obviously didn't work. I'm sorry if there is a topic like that, but I didn't found it.I have a restriction to install modules.