Skip to content

Commit

Permalink
route with dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
Violet-Bora-Lee committed Aug 16, 2024
1 parent 15eed28 commit a789455
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// App.js
import React from 'react';
import React, { Suspense, lazy } from 'react';
import { BrowserRouter as Router, Route, Link, Routes } from 'react-router-dom';
import Home from './components/Home';
import Dashboard from './components/Dashboard';
import Profile from './components/Profile';

const Home = lazy(() => import('./components/Home'));
const Dashboard = lazy(() => import('./components/Dashboard'));
const Profile = lazy(() => import('./components/Profile'));

function App() {
return (
Expand All @@ -17,11 +18,13 @@ function App() {
</ul>
</nav>

<Routes>
<Route path="/" element={<Home />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/profile" element={<Profile />} />
</Routes>
<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/profile" element={<Profile />} />
</Routes>
</Suspense>
</div>
</Router>
);
Expand Down

0 comments on commit a789455

Please sign in to comment.