我正在嘗試為我的 react.js 網站實作一個主頁。我的布局很好,我的代碼編譯沒有問題。
但是,當我單擊我的按鈕時,我在網站應用程式TypeError: navigate.push is not a function上收到以下錯誤: navigate.push("/quiz")
我是新手,如果有人能幫助我,我會很高興的!
這是我的代碼:
import { Button } from "@material-ui/core";
import { Container } from "@material-ui/core";
import { useNavigate } from "react-router-dom";
import "./Home.css";
const Home = () => {
const navigate = useNavigate();
const sendSubmit = () => {
navigate.push("/quiz");
};
return (
<Container className="content">
<h1 id="quiz-title">Phishing Quiz</h1>
<h2 class="question-text">
Do you think you can beat our phishing quiz?
</h2>
<p className="description">
{" "}
There are many social engineering attacks on internet however not all of
them are good enough to trick users. However there are some scams that
are identical to original websites and usually most of the users get
tricked by them.
</p>
<p className="description">
Do you think you are smart enough to handle these attacks?
</p>
<p className="description">
We are challenging you with our phishing quiz which will show you
examples of really good social engineering attacks on internet. We hope
you can pass!
</p>
<p>""</p>
<Button
className="button"
variant="contained"
color="primary"
size="large"
onClick={sendSubmit}
>
Start Quiz
</Button>
</Container>
);
};
export default Home;
uj5u.com熱心網友回復:
可以用下面的代碼檢查
import {useNavigate} from 'react-router-dom';
并在 Home 箭頭功能內
const navigate = useNavigate();
const sendSubmit = () => {
navigate("/quiz");
};
uj5u.com熱心網友回復:
發出推送您的代碼必須如下所示:
const Home = () => {
const navigate = useNavigate();
// delete push
const sendSubmit = () => {
navigate("/quiz");
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/365646.html
標籤:javascript 反应 按钮 反应路由器 材质-ui
