-
글쓴이글
-
2022년 4월 16일 21:15 #31888
고진규참가자import axios from "axios";
import { useHistory } from "react-router-dom";
function Logging(){
const username = document.getElementById("username");
const password = document.getElementById('password');
let history = useHistory();
//history.push('/Translation');
axios({
method:"POST",
url: '~~~~~~~~~~',
data:{
"username": username?.value,
"password": password?.value
}
}).then((res)=>{//성공
console.log(res);
console.log(res.data.refresh_token);
localStorage.setItem("re-token",res.data.refresh_token);
localStorage.setItem("ac-token",res.data.access_token);
window.alert(JSON.stringify(res.data.username).replace(/\"/gi, "")+"님 접속 성공");
}).catch(error=>{
console.log(error);
window.alert("접속실패.");
});
}
export default Logging;이런식으로하고있는데
let history = useHistory(); 이것만 적으면 invalid hook call 오류가 생기더라고요,,왜이럴까요..?
// eslint-disable
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import { Link,Route,Switch} from 'react-router-dom';
import React ,{useState}from 'react';
import Translation from './Translation.js';
import Login from './Login.js';
import Main from './Main.js';
import Sg from './Sg';
import { BrowserRouter } from 'react-router-dom';function App() {
return (
<div>
<BrowserRouter>
<Route exact path='/' >
<Main/>
</Route>
<Route exact path='/sg' >
<Sg/>
</Route>
<Route exact path='/Login' >
<Login/>
</Route>
<Route exact path='/Translation' >
<Translation/>
</Route>
</BrowserRouter>
</div>
);
}export default App;
2022년 4월 16일 21:16 #31889
고진규참가자"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/react-fontawesome": "^0.1.17",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
"express": "^4.17.3",
"gapi-script": "^1.2.0",
"google-auth-library": "^7.14.1",
"mysql": "^2.18.1",
"react": "^17.0.2",
"react-bootstrap": "^2.1.2",
"react-cookie": "^4.1.1",
"react-dom": "^17.0.2",
"react-feather": "^2.0.9",
"react-google-login": "^5.2.2",
"react-icons": "^4.3.1",
"react-router-dom": "^5.3.0",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.4"
},이정보도 필요할까봐,..적었습니다..
2022년 4월 16일 22:51 #31894
codingapple키 마스터보통 라이브러리 설치가 잘못된 경우가 많습니다 새로운 프로젝트에 설치해봅시다
지금 서버프로젝트랑 같은 폴더에 리액트 설치해서 쓰는거같은데
프론트랑 백엔드는 다른 폴더에 개발하는게 좋습니다
-
글쓴이글
- 답변은 로그인 후 가능합니다.