score:1

Accepted answer
import React from "react";
import { Switch, Route } from "react-router-dom";
import BaseLayout from "./BaseLayout";
import routes from "./routes";

export default class extends React.Component {
  state = {
    withHeaderSidenav: true
  };

  showHeaderSidenav = (withHeaderSidenav = true) => {
    this.setState({ withHeaderSidenav });
  };

  render() {
    return (
      <BaseLayout withHeaderSidenav={this.state.withHeaderSidenav}>
        <Switch>
          {routes.map(route => (
            <Route
              exact
              key={route.path}
              path={route.path}
              render={() => (
                <route.component
                  showHeaderSidenav={() =>
                    this.showHeaderSidenav(route.withHeaderSidenav)
                  }
                />
              )}
            />
          ))}
        </Switch>
      </BaseLayout>
    );
  }
}

Related Query

More Query from same tag