У меня есть три компонента, и для навигации между ними я использую маршруты реагирования.
import React from "react";
import {HashRouter, Route, Switch, Redirect} from 'react-router-dom';
import Main from './components/main/main.component';
import SecondView from './components/secondview/secondview.component';
import ThirdView from './components/thirdview/thirdview.component';
import Traineeship from './components/traineeship/traineeships.component';
import InformationFilter from "./components/information/information-filter.component";
import InformationJob from "./components/information/information-job.component";
const AppRoutes = () => (
<HashRouter>
<Switch>
<Route path='/information-filter' component={InformationFilter}/>
<Route path='/information-job' component={InformationJob}/>
<Route path='/traineeships' component={Traineeship}/>
</Switch>
</HashRouter>
);
export default AppRoutes;
В компоненте InformationFilter я использую ссылку для перехода к другому компоненту, например:
<Link to={{
pathname: '/information-job',
state: {industry: this.state.selectedIndustry, job: this.state.selectedJob}
}}>
Я вижу параметры, доступные в InformationJob, и из информационного задания, которое я прохожу, используя Link to Traineeship, но проблема в том, что когда я возвращаюсь из Traineeship, эта часть в InformationJob:
componentDidMount() {
console.log(this.props.location.state);
}
пуста, что является лучшимтаким образом, чтобы я мог передать параметры из компонента A в B, а затем в C, чтобы у меня не было никаких проблем при нажатии кнопки назад.
Есть идеи по этому поводу?