使用反应路由器dom时单击后退按钮时出错

时间:2021-01-26 13:18:04

标签: reactjs ionic-framework react-router-dom

当我在使用 history.push 导航到如下所示的页面后单击后退按钮时,我正在开发一个 ionic react 应用程序

            history.push({
              pathname: '/mutiplequiz',
              state: 
                  { 
                      testUser,
                      testTime,
                      testSubjects
                  }
            })

在 Mutiplequiz 页面上,当我按后退按钮时出现此错误 enter image description here

这是 multiplequiz 页面上的代码

import React ,{useRef,useEffect,useState} from 'react';  
import { IonButtons, IonContent, IonHeader,IonIcon, IonMenuButton, IonTitle, IonToolbar,IonImg,IonButton,isPlatform, IonGrid,IonRow,IonCard,IonCardContent,IonCol, IonList,IonItem,IonLabel,IonListHeader, IonLoading, IonSpinner, IonAlert  } from '@ionic/react';
import { History, LocationState } from "history";
import { Link, useHistory, } from "react-router-dom";
export type historyData={
    testSubjects:[],
    year:number,
    testTime:number,
    testUser:string
}

const MutipleQuiz: React.FC = () => {

    const history: History<historyData>= useHistory();
    const { testSubjects,testTime,testUser }= history.location.state;
    useEffect( ()=>{
     
    },[]);
}

export default MutipleQuiz;

如何返回而不出现此错误

0 个答案:

没有答案