简体   繁体   中英

how to change the title and icon in react app?

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 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;

you can change the logo from./assets/index.htm and change the href.

and input your image to./assets/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM