I am making a react app. But in the title bar, it is showing 'React App' with React logo. I want to change it to my website name and logo, and how can I do that ?
If you want to change the title, you can go to: public/index.html
, and then change the <title>React App </title>
To change your logo, go to the public folder and change the favicon.ico
.
If you follow these steps, your logo and title will get changed.
If it helps you, please mark as accepted answer.
you can change title and icon on public/index.html
in react project.
<head>
...
...
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<title>React App</title>
...
...
</head>
Making changes in public/index.html
would only change the default values (title and favicon), and it will be set for all pages. More on this method and some (complex) alternatives in the official docs: https://create-react-app.dev/docs/title-and-meta-tags/
...or you can use React Helmet, a third-party library recommended in the official docs as well: https://github.com/nfl/react-helmet. It will allow you to set page title/favicon/other head
elements from the components itself.
Example code using React Helmet:
import {Helmet} from "react-helmet";
class Application extends React.Component {
render () {
return (
<div className="application">
<Helmet>
<meta charSet="utf-8" />
<title>My Title</title>
<link rel="canonical" href="http://example.com/example" />
</Helmet>
...
</div>
);
}
};
You can change your page title by doing something like this.
const pageTitle = `${title}`;
Then:
document.title = pageTitle;
To change page Title
and Icon
of the page use following steps
- Inside your projects public folder open
index.html
- Update the title to your project name
<title>Project Name</title>
- To change icon
- Duplicate and rename your app logo to
favicon.ico
and replace in public folder - Replace your
logos.png
to your logos - Save and reload the application
you can change the logo from ./assets/index.htm and change the href.
and input your image to ./assets/
I just had the same issue. I have build a generic website and the URL to the favicon is also stored in the DB. So no chance to set it already in the HTML file.
function App(): React.JSX.Element {
const [config, setConfig] = useState<types.ProjectConfig | null>(null)
useEffect(() => {
getProjectConfig().then((config: types.ProjectConfig) => {
const favicon = document.querySelector("link[rel~='icon']") as HTMLLinkElement
if (favicon) {
favicon.href = config.faviconURL // In your case just replace this with the URL in string format
}
document.title = config.pageTitle
setConfig(config)
})
}, [])
This works for me :)
© 2022 - 2024 — McMap. All rights reserved.