REACTJS dává následující chyba: TypeError: navigovat.push není funkce

0

Otázka

Snažím se zavést domovské stránce pro můj react.js webové stránky. Moje rozložení je v pořádku a můj kód zkompiluje bez problémů.

Nicméně, když jsem klepněte na tlačítko moje tlačítko jsem dostat následující chybu na webových stránkách aplikace: TypeError: navigate.push is not a function na řádek, který říká: navigate.push("/quiz")

Jsem nový na to reagovat a jestli někdo mi může pomoci, byl bych vděčný!

Tady je můj kód:

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;

2

Nejlepší odpověď

0

můžete zkontrolovat s níže kód

import {useNavigate} from 'react-router-dom';

a uvnitř Domů šipka funkce

const navigate = useNavigate();

const sendSubmit = () => {
    navigate("/quiz");
};
2021-11-23 02:27:13
0

vydal se zasadila váš kód musí vypadat takto:

const Home = () => {
const navigate = useNavigate();

// delete push
const sendSubmit = () => {
navigate("/quiz");
};
2021-11-23 17:30:18

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................