-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathNavigation.tsx
46 lines (39 loc) · 1.17 KB
/
Navigation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Suspense } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { Routes, Route, NavLink, Navigate } from 'react-router-dom';
import { routes } from './routes';
import logo from '../logo.svg'
export const Navigation = () => {
return (
<Suspense fallback={ <span>Loading...</span> }>
<BrowserRouter>
<div className="main-layout">
<nav>
<img src={logo} alt="React Logo" />
<ul>
{
routes.map(({ to, name }) => (
<li key={to}>
<NavLink to={to} className={({ isActive }) => isActive ? 'nav-active' : ''} replace> {name} </NavLink>
</li>
))
}
</ul>
</nav>
<Routes>
{
routes.map(({ path, Component }) => (
<Route
key={path}
path={path}
element={<Component />}
/>
))
}
<Route path="/*" element={<Navigate to={routes[0].to} replace />} />
</Routes>
</div>
</BrowserRouter>
</Suspense>
)
}