score:1

import React ,{ useState, useEffect } from "react";
import { createBrowserHistory } from "history";
import { BrowserRouter, Route, Switch, withRouter, Redirect } from "react-router-dom";
import { useSelector } from "react-redux";
import JsonData from "./data/data.json";
import axios from "axios";

const App = () => {
  const [landingPageData, setLandingPageData] = useState({});
  useEffect(() => {
    setLandingPageData(JsonData);
  }, []);

  const { user: currentUser } = useSelector(state => state.auth);

  const hist = createBrowserHistory();

  return (
    <BrowserRouter history={hist}>
      {currentUser ? (
        <div>
          <Layout>
            <Switch>
              <Route path="/home" render={() => <Header data={landingPageData.Header} />} />
              <Route path="/destinations" render={() => <Destinations data={landingPageData.Destinations} />} />
            </Switch>
          </Layout>
        </div>
      ) : (
        <div>
          <Layout >
            <Switch>
              <Route path="/register-page" component={Register} />
              <Route path="/login" component={Login} />
            </Switch>
          </Layout>
        </div>
      )}
    </BrowserRouter>
  );
};

export default App;


Related Query

More Query from same tag