Programming/React

[ React ] GET ν˜ΈμΆœν•˜μ§€λ„ μ•Šμ•˜λŠ”λ° 계속 GET ν˜ΈμΆœλ˜λŠ” ν˜„μƒ

seulye 2024. 8. 8. 11:08

 

  const onClickLogin = () => {
    axios
      .post(`/api/comm/user/signin`, {
        id: id,
        password: pw,
      })
      .then((response) => {
        console.log(response.data);
      })
      .catch((error) => {
        console.log(error);
      });
  };

둜그인 κΈ°λŠ₯을 μˆ˜ν–‰ν•˜λŠ” ν•¨μˆ˜λ₯Ό μž‘μ„±ν–ˆλŠ”λ°, 계속 get이 μ°νžŒλ‹€.

 

λ¬ΌμŒν‘œκ°€ λΆ™λŠ” μ΄μœ λŠ”,

HTML 폼이 GET λ©”μ†Œλ“œλ‘œ 제좜되면, 폼 ν•„λ“œ 값이 μžλ™μœΌλ‘œ 쿼리 슀트링으둜 μΆ”κ°€λ˜κΈ° λ•Œλ¬Έμ΄λ‹€.

 

const onClickLogin = (event) => {
    event.preventDefault();
    axios.post(`/api/comm/user/signin`,{
      id:id,
      password:pw
    }) 
    .then((response) => {
      console.log(response.data)
    })
    .catch((error) => {
      console.log(error);
    });
  }

 

κ·Έλž˜μ„œ event.preventDefault(); 이뢀뢄 μΆ”κ°€. μ–΄λ–€ 이벀트λ₯Ό λͺ…μ‹œμ μœΌλ‘œ μ²˜λ¦¬ν•˜μ§€ μ•Šμ€ 경우, ν•΄λ‹Ή μ΄λ²€νŠΈμ— λŒ€ν•œ μ‚¬μš©μž μ—μ΄μ „νŠΈμ˜ κΈ°λ³Έ λ™μž‘μ„ μ‹€ν–‰ν•˜μ§€ μ•Šλ„λ‘ μ§€μ •

 

https://developer.mozilla.org/ko/docs/Web/API/Event/preventDefault

 

Event.preventDefault() - Web API | MDN

Event μΈν„°νŽ˜μ΄μŠ€μ˜ preventDefault() λ©”μ„œλ“œλŠ” μ–΄λ–€ 이벀트λ₯Ό λͺ…μ‹œμ μœΌλ‘œ μ²˜λ¦¬ν•˜μ§€ μ•Šμ€ 경우, ν•΄λ‹Ή μ΄λ²€νŠΈμ— λŒ€ν•œ μ‚¬μš©μž μ—μ΄μ „νŠΈμ˜ κΈ°λ³Έ λ™μž‘μ„ μ‹€ν–‰ν•˜μ§€ μ•Šλ„λ‘ μ§€μ •ν•©λ‹ˆλ‹€.

developer.mozilla.org