Home > Mobile >  Showing current/dynmaic url in react tab
Showing current/dynmaic url in react tab

Time:09-28

Simple problem which I cannot seem to find the answer to. Currently I have built a website with react and when a user opens a new tab it shows the same favicon, image and hard coded title on every tab. I simply wish to do as stackoverflow, and may other web pages and dynamically show the page title in the tab. enter image description here

My current index.html in the react app just has the hard-coded title. Does anyone know how to change this to show the current web url ? Thanks!

 <title>My Website </title>

CodePudding user response:

Found the answer for anyone else looking for this. Simply remove the title. The hard coded title did not allow the page to show dynamically in the title. After removing them the react-router route renders in the tab.

CodePudding user response:

this function will change the title of your page .

function setTitle (arg){
   document.title = arg ;
 }

then in your component you can do like below :

export default function Component() {

setTitle("your title") ;

 function setTitle (arg){
   document.title = arg ;
 }

}
  • Related