-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
33 lines (23 loc) · 982 Bytes
/
index.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
import { RouteObject, useRoutes } from "react-router-dom";
import { NotFound } from "features/misc";
import { useAuth } from "lib/auth";
import { protectedRoutes } from "./protected";
import { publicRoutes } from "./public";
/*
Routes are separated into either public or protected
Protected routes require User authentication to access (handled by AuthProvider)
For both protected and public routes, this global routes only
route to feature root subdirectory:
e.g. {...}.com/some-feature
Further sub-routing are managed by the feature itself:
e.g. /src/features/some-feature/routes/
*/
export const AppRoutes = () => {
const auth = useAuth();
//{ path: "/", element: <Landing /> }
const commonRoutes: RouteObject[] = [];
const fallbackRoute = [{ path: "*", element: <NotFound /> }];
const routes = auth.user ? protectedRoutes : publicRoutes;
const element = useRoutes([...routes, ...commonRoutes, ...fallbackRoute]);
return <>{element}</>;
};