codingspecialist / Springboot-JPA-React-JWT-CRUD

5 stars 10 forks source link

navigate 로 화면 이동 #3

Open codingspecialist opened 3 weeks ago

codingspecialist commented 3 weeks ago

import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom';

function JoinForm() { const [user, setUser] = useState({ username: '', password: '', // 기타 필요한 사용자 정보 });

const navigate = useNavigate();

const submitJoin = (e) => { e.preventDefault(); fetch("http://localhost:8000/join", { method: "POST", headers: { "Content-Type": "application/json; charset=utf-8" }, body: JSON.stringify(user) }).then(res => { return res.text(); }).then(res => { if (res === "ok") { navigate("/loginForm"); // navigate를 사용하여 경로 이동 } else { alert('회원가입 실패'); } }); };

codingspecialist commented 3 weeks ago

옛날 코드

props.history.push("/loginForm");