fix: 登录成功后跳转首页
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onLogin: (token: string) => void
|
onLogin: (token: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function LoginPage({ onLogin }: Props) {
|
export default function LoginPage({ onLogin }: Props) {
|
||||||
|
const navigate = useNavigate()
|
||||||
const [username, setUsername] = useState('')
|
const [username, setUsername] = useState('')
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
@@ -31,6 +33,7 @@ export default function LoginPage({ onLogin }: Props) {
|
|||||||
|
|
||||||
localStorage.setItem('token', data.access_token)
|
localStorage.setItem('token', data.access_token)
|
||||||
onLogin(data.access_token)
|
onLogin(data.access_token)
|
||||||
|
navigate('/')
|
||||||
} catch {
|
} catch {
|
||||||
setError('网络错误')
|
setError('网络错误')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user