navigate.push 不是函数
navigate.push is not a function
我在 React Reuter 中遇到错误 dom 与 navigate.push 相关的版本不是函数。
以下错误扰乱了我整个干净的代码,如果有人帮助我解决这个问题,那就太好了。
This is my code
import { Link, useNavigate } from "react-router-dom";
import { auth } from "./firebase";
function Login() {
const navigate = useNavigate();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const signIn = (e) => {
e.preventDefault();
auth
.signInWithEmailAndPassword(email, password)
.then((auth) => {
navigate.push("/");
})
.catch((error) => alert(error.message));
};
const register = (e) => {
e.preventDefault();
auth
.createUserWithEmailAndPassword(email, password)
.then((auth) => {
//it successfully created a new user with email and password
if (auth) {
navigate.push("/");
}
})
.catch((error) => alert(error.message));
};
如果您使用的是 React Router v6:
使用 navigate("/")
而不是 navigate.push("/")
我在 React Reuter 中遇到错误 dom 与 navigate.push 相关的版本不是函数。 以下错误扰乱了我整个干净的代码,如果有人帮助我解决这个问题,那就太好了。
This is my code
import { Link, useNavigate } from "react-router-dom";
import { auth } from "./firebase";
function Login() {
const navigate = useNavigate();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const signIn = (e) => {
e.preventDefault();
auth
.signInWithEmailAndPassword(email, password)
.then((auth) => {
navigate.push("/");
})
.catch((error) => alert(error.message));
};
const register = (e) => {
e.preventDefault();
auth
.createUserWithEmailAndPassword(email, password)
.then((auth) => {
//it successfully created a new user with email and password
if (auth) {
navigate.push("/");
}
})
.catch((error) => alert(error.message));
};
如果您使用的是 React Router v6:
使用 navigate("/")
而不是 navigate.push("/")