React에서 index.html의 title을 설정 값으로 변경하려면, public 폴더의 index.html 파일에서 title 태그 내부의 값을 설정해야 합니다.
기본적으로, index.html 파일의 title은 public 폴더의 index.html 파일의 <title> 태그에 하드코딩되어 있습니다.
예를 들어, public/index.html 파일에서 title 값을 설정하려면, 다음과 같이 작성합니다.
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<!-- title 값 설정 -->
<title>%REACT_APP_TITLE%</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
여기서 %REACT_APP_TITLE%은 환경 변수로 설정한 값입니다. 이 값을 설정하려면, .env 파일에 다음과 같이 추가합니다.
makefileREACT_APP_TITLE=My App
이제 React 앱을 실행하면, public/index.html 파일의 title 값이 환경 변수로 설정한 값으로 변경됩니다.