forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RouteDefs.jsx
59 lines (56 loc) · 1.65 KB
/
RouteDefs.jsx
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
import App from "App";
import {
Footer,
Header,
Home,
PlayMeta,
DefMeta,
PageNotFound,
PlayIdeas,
TechStack
} from "common";
import PlayList from "common/playlists/PlayList";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { NhostClient, NhostReactProvider } from "@nhost/react";
import useGetPlays from "common/hooks/useGetPlays";
const nhost = new NhostClient({
backendUrl: process.env.REACT_APP_NHOST_BACKEND_URL || "",
});
const RouteDefs = () => {
const [loading, error, plays] = useGetPlays();
const success = !loading && !error && !!plays.length;
return (
<NhostReactProvider nhost={nhost}>
<BrowserRouter>
<Header />
<DefMeta />
<Routes>
<Route path='/' element={<Home />} />
<Route path="/tech-stacks" element={<TechStack />} />
<Route path='/plays' element={<App />}>
<Route
index
element={
<PlayList loading={loading} plays={success ? plays : []} />
}
/>
{success &&
plays?.map((play, index) => (
<Route
key={index}
path={play?.path}
element={<PlayMeta key={index} play={play} />}
>
<Route path=':param' element={<PlayMeta {...play} />} />
</Route>
))}
</Route>
<Route path='/ideas' element={<PlayIdeas />} />
<Route path='/*' element={<PageNotFound loading={loading} />} />
</Routes>
<Footer />
</BrowserRouter>
</NhostReactProvider>
);
};
export default RouteDefs;