Skip to content

Instantly share code, notes, and snippets.

@akhil-gautam
Created May 12, 2019 14:41
Show Gist options
  • Save akhil-gautam/5fab846309c5ca35e65258268dbcc482 to your computer and use it in GitHub Desktop.
Save akhil-gautam/5fab846309c5ca35e65258268dbcc482 to your computer and use it in GitHub Desktop.
App.js file which is the root file which will be mounted to the dom and where routing will be configured.
import React, { Suspense, lazy } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import './App.css';
// importing the Home component by default
import Home from './Components/Home';
// importing other components using Dynamic Import
const About = lazy(() =>
import(/* webpackChunkName: "About" */ './Components/About'));
const Contact = lazy(() =>
import(/* webpackChunkName: "Contact" */ './Components/ContactUs'));
const App = () => (
<Router>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
<Route path="/contact" component={Contact}/>
</Switch>
</Suspense>
</Router>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment