React - img

Corini·2022년 5월 3일
0

React (완료)

목록 보기
15/16

https://velog.velcdn.com/images/hoho_0815/post/7ee846f3-2c07-4ddd-9ead-b5b003549055/image.jpg

React - img

App 컴포넌트에 img 삽입

현재 폴더 구조

https://user-images.githubusercontent.com/87301268/163106269-9aa9ddcc-c8cf-4e19-9a63-d7b7baa62ab6.JPG

App.js

import './App.css';
import { BrowserRouter, Route, Routes } from 'react-router-dom';

import Home from './pages/Home';
import New from './pages/New';
import Edit from './pages/Edit';
import Diary from './pages/Diary';

function App() {
  return (
    <BrowserRouter>
      <div className="App">
        <h2>App.js</h2>

        <img src={process.env.PUBLIC_URL + `/assets/emotion1.png`} />

        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/new" element={<New />} />
          <Route path="/edit" element={<Edit />} />
          <Route path="/diary/:id" element={<Diary />} />
        </Routes>
      </div>
    </BrowserRouter>
  );
}

export default App;
<img src={process.env.PUBLIC_URL + `/assets/emotion1.png`} />
  • process.env.PUBLIC_URL 은 어떤 위치에 있든 /public 을 가리킵니다.

https://user-images.githubusercontent.com/87301268/163106720-3771e9ff-658a-42b6-a9e3-49193a2ceadb.JPG

참고

profile
Coding is playing!

0개의 댓글