I
I
Ivan2019-06-02 19:02:22
React
Ivan, 2019-06-02 19:02:22

Is it possible to somehow write the component of the active Route to the state?

Is it possible to somehow write the component of the active Route to the state?
Those. I need to write the ContentIndex to the state when it is active

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);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question