-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
72 lines (58 loc) · 2.39 KB
/
App.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {
// NavRoutes, /* //? Uncomment to use JSX form of Routes and comment NavRoutesObject */
NavRoutesObject,
} from './routes/NavRoutes'
import { MainNav } from './navigation/MainNav'
// import { BlogRoutes } from './routes/BlogRoutes' /* //? Uncomment to see console warning */
// import appStyle from './App.module.css'
import './App.module.css'
import { useState } from 'react'
import URApp from './useRoutes/URApp'
import { withContainer } from './hoc/sharedWrapper'
/* //> IMPORTANT: Resource Material samples are based from v4 and the current
REACT-ROUTER-DOM IS CURRENTLY IN V6
Due to the outdated version, v6 of React Router will be used instead
! Using multiple <Routes> appear to work in the UI but it generates a warning on the console whenever the current location is not the path specified inside <Route>
ie. <Route path="/blog/*" element={<BlogNav />} />
above generates a warning `No routes matched location "/${insert current pathName if not main dir}"`
*/
/* //* Transferred to ./hoc/sharedWrapper.js
const { pageWrapper } = appStyle
const withContainer = (Comp) => {
return () => (
<div className={pageWrapper} >
<Comp />
</div>
)
}
*/
/* //? JSX way of creating Routes -- Uncomment this and comment out ALtMainContent if desired */
// const MainContent = withContainer(NavRoutes)
/* Routing with useRoutes */
const AltMainContent = withContainer(NavRoutesObject)
const App = () => {
const [isPrimary, setIsPrimary] = useState(true)
const handleUIChange = () => {
setIsPrimary(prev => !prev)
}
/* //> THIS ternary + state SETUP WILL PREVENT GOING TO `/useRoutes/*` via the URL;
because the initial isPrimary state is false (each page reload will reset state) */
return isPrimary
? (
<>
<MainNav handleUIChange={handleUIChange} />
{/* //> BlogRoutes contains a separate <Routes>
generates a console warning whenever current location is not '/blog/*'
//* `No routes matched location "/${insert current pathName if not main dir}`
still appears to work though in the UI
//? Uncomment to see console warning */}
{/* <BlogRoutes /> */}
{/* //? Uncomment if JSX Routes desired and comment out AltMainContent */}
{/* <MainContent /> */}
<AltMainContent />
</>
) : (
<URApp handleUIChange={handleUIChange} />
)
}
export default App