12.08 TIL

아름·2023λ…„ 12μ›” 8일
0
post-thumbnail

μ•Œκ³ λ¦¬μ¦˜ μ½”λ“œμΉ΄νƒ€

μ•Œκ³ λ¦¬μ¦˜ 풀이1

μ•„μ›ƒμ†Œμ‹± ν”„λ‘œμ νŠΈ

였늘 μ§„ν–‰ν•œ 것

UI μ™„μ„±

둜그인 μƒνƒœμ— λ”°λ₯Έ Header μ „ν™˜

  • λ‘œκ·Έμ•„μ›ƒ μƒνƒœμ—μ„œλŠ” νšŒμ›κ°€μž…, 둜그인 λ²„νŠΌμœΌλ‘œ μ „ν™˜
  • 둜그인 μƒνƒœμ—μ„œλŠ” λ§ˆμ΄νŽ˜μ΄μ§€, κ²Œμ‹œλ¬Ό 올리기, λ‘œκ·Έμ•„μ›ƒ λ²„νŠΌμœΌλ‘œ μ „ν™˜
  • μ‚Όν•­μ—°μ‚°μžλ‘œ 둜그인 μƒνƒœλ₯Ό λ°˜μ˜ν•΄μ£ΌκΈ°
import { Link } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { logout } from '../../redux/modules/authSlice';

<Stbutton>
          {isLogin ? (
            <>
              <Link to="/profile">
                <button>λ§ˆμ΄νŽ˜μ΄μ§€</button>
              </Link>
              <Link to="/Write">
                <button>κ²Œμ‹œλ¬Ό 올리기</button>
              </Link>
              <button
                onClick={() => {
                  alert('정말 λ‘œκ·Έμ•„μ›ƒ ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?');
                  dispatch(logout());
                }}
              >
                λ‘œκ·Έμ•„μ›ƒ
              </button>
            </>
          ) : (
            <>
              <Link to="/register">
                <button>νšŒμ›κ°€μž…</button>
              </Link>
              <Link to="/login">
                <button>둜그인</button>
              </Link>
            </>
          )}
        </Stbutton>

Header.jsx, styles.js λ¦¬νŒ©ν† λ§

  • νŒ€ ν”„λ‘œμ νŠΈ rules에 따라 styled-components λΆ„λ¦¬ν•˜μ—¬ 관리
// Common 폴더
// Header.jsx
import {
  StHeader,
  StLogo,
  StBtnInputWrapper,
  Stbutton,
  SearchContainer,
  SearchInput,
  SearchImage
} from './styles';

// styles.js
import styled from 'styled-components';

export const StBtnInputWrapper = styled.div`
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 20px;
  gap: 50px;
`;
.
.

였λ₯˜ λ°œμƒ

문제

  • 상황
    pages 폴더 > Login.jsx, Register.jsxμ—μ„œ μž‘μ—…
    component 폴더 > Register 폴더 > Signin.jsx, Signup.jsx둜 λ¦¬νŒ©ν† λ§

κΈ°μ‘΄μ—λŠ” Login.jsx와 Register.jsxμ—μ„œ μ­‰ μž‘μ—…μ„ ν•΄μ£Όκ³  μžˆμ—ˆλ‹€. μ–΄λŠ 정도 기술 κ΅¬ν˜„ λΌμ„œ μ»΄ν¬λ„ŒνŠΈ 뢄리λ₯Ό μœ„ν•΄ λ¦¬νŒ©ν† λ§μ„ ν•˜κ³  있던 와쀑 였λ₯˜ λ°œμƒ..!

μ–΄μ œ λ°œμƒ ν–ˆλ˜ 였λ₯˜ λ©”μ‹œμ§€μ™€ ꡉμž₯히 ν‘μ‚¬ν–ˆλ‹€. μ–΄μ œλ„ κ²°κ΅­μ—” 해결을 ν•˜μ§€ λͺ»ν•΄μ„œ μ½”λ“œλ₯Ό λ‹€μ‹œ μ§°μ—ˆλŠ”λ° μ˜€λŠ˜λ„ 또 λ˜‘κ°™μ€ 였λ₯˜γ… γ…  이 μƒνƒœλ‘œλŠ” λ‹€λ₯Έ νŽ˜μ΄μ§€μ—μ„œ λ‘œμ§μ„ μ§œλ„ 계속 같은 λ¬Έμ œκ°€ λ°œμƒ ν•  κ±° κ°™μ•„μ„œ νŒ€μ›λΆ„λ“€κ»˜ 도움을 μš”μ²­ν•΄λ΄€λ‹€.

ν•΄κ²°

node_modules 폴더도 μ§€μš°κ³  μž¬μ„€μΉ˜ν•˜κ³  export, import의 경둜 λ¬Έμ œλŠ” μ•„λ‹Œμ§€ μ˜€νƒ€λŠ” μ—†λŠ”μ§€ 일일히 λͺ¨λ“  μ½”λ“œλ₯Ό λ‹€ ν™•μΈν•΄λ΄€λŠ”λ° μ „ν˜€ λ¬Έμ œκ°€ μ—†μ—ˆλ‹€. νŒ€μ›μ΄ λ³΄μ‹œκΈΈ κ³΅ν†΅μ μœΌλ‘œ modules/authSlice의 경둜 문제라고 ν•˜μ…¨λ‹€. 경둜λ₯Ό 잘 읽지 λͺ»ν•˜λŠ” κ±° κ°™μ•„μ„œ λͺ¨λ“  파일의 import 경둜λ₯Ό ν•˜λ‚˜ν•˜λ‚˜ μ œλŒ€λ‘œ λͺ…μ‹œλ₯Ό 해쀬닀.

// signin.jsx
import { login } from 'redux/modules/authSlice';
↓
import { login } from '../../redux/modules/authSlice';

// configStore.js
import authSlice from 'redux/modules/authSlice';
↓
import authSlice from '../modules/authSlice';

이와 같이 λ°”κΏ”μ£Όλ‹ˆ 해결이 됐닀. μ™œ 경둜λ₯Ό μ œλŒ€λ‘œ 읽지 λͺ»ν•˜λŠ”μ§€λŠ” λͺ¨λ₯΄κ² μ§€λ§Œ 이와 λΉ„μŠ·ν•œ 였λ₯˜κ°€ λ°œμƒν–ˆμ„ λ•Œμ˜ 해결법을 μ•Œκ²Œ λμœΌλ‹ˆ 그걸둜 닀행이닀!

profile
λ‚΄ κΏˆμ€ 개발자

0개의 λŒ“κΈ€