Можно ли как-то записать компонент активного Route в стейт?
Т.е. мне нужно
ContentIndex записать в стейт когда он будет активен
import React, {Component,Suspense,lazy} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {ConnectedRouter} from 'connected-react-router';
import ScrollToTop from 'react-router-scroll-top';
import {Route, Switch} from 'react-router-dom';
import Head from '../common/Head';
import Header from '../common/Header';
import Footer from '../common/Footer';
const ContentIndex = lazy(() => import('../pages/ContentIndex'));
class Root extends Component {
constructor(props) {
super(props);
this.state = { Component : null }
}
render() {
return (
<ConnectedRouter history={this.props.history}>
<ScrollToTop>
<Head/>
<Header/>
<div className="all-data">
<Suspense fallback={<h2>Product list is loading...</h2>}>
<Switch>
<Route
exact
path={"/"}
render={ContentIndex}
/>
</Switch>
</Suspense>
</div>
<Footer/>
</ScrollToTop>
</ConnectedRouter>
)
}
}
function matchDispatchToProps(dispatch) {
return bindActionCreators({ }, dispatch)
}
export default connect(state => ({router: state.router}), matchDispatchToProps)(Root);