lincd-cli 0.2.39 → 0.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/app-with-backend/.run/start.run.xml +12 -0
- package/defaults/app-with-backend/package.json +1 -0
- package/defaults/app-with-backend/src/layout/Header.tsx +7 -2
- package/defaults/app-with-backend/src/pages/PageNotFound.tsx +11 -0
- package/defaults/app-with-backend/src/pages/Signin.tsx +12 -0
- package/defaults/app-with-backend/src/routes.tsx +38 -8
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<component name="ProjectRunConfigurationManager">
|
|
2
|
+
<configuration default="false" name="start" type="js.build_tools.npm" nameIsGenerated="true">
|
|
3
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
+
<command value="run" />
|
|
5
|
+
<scripts>
|
|
6
|
+
<script value="start" />
|
|
7
|
+
</scripts>
|
|
8
|
+
<node-interpreter value="project" />
|
|
9
|
+
<envs />
|
|
10
|
+
<method v="2" />
|
|
11
|
+
</configuration>
|
|
12
|
+
</component>
|
|
@@ -9,8 +9,13 @@ export function Header() {
|
|
|
9
9
|
<header className={style.header}>
|
|
10
10
|
<h1>${name}</h1>
|
|
11
11
|
<nav className={style.menu}>
|
|
12
|
-
{Object.keys(ROUTES).map(key => {
|
|
13
|
-
|
|
12
|
+
{Object.keys(ROUTES).map((key) => {
|
|
13
|
+
if (ROUTES[key].excludeFromMenu) return null;
|
|
14
|
+
return (
|
|
15
|
+
<Link key={key} to={ROUTES[key].path}>
|
|
16
|
+
{ROUTES[key].label || key}
|
|
17
|
+
</Link>
|
|
18
|
+
);
|
|
14
19
|
})}
|
|
15
20
|
</nav>
|
|
16
21
|
</header>
|
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import React, {lazy, Suspense} from 'react';
|
|
2
2
|
import {Route, Routes} from 'react-router-dom';
|
|
3
3
|
import {Spinner} from './components/Spinner';
|
|
4
|
+
import {RequireAuth} from 'lincd-auth/lib/components/RequireAuth';
|
|
5
|
+
import PageNotFound from './pages/PageNotFound';
|
|
4
6
|
|
|
5
7
|
//In React 18 you can use 'lazy' to import pages only when you need them.
|
|
6
8
|
//This will cause webpack to create multiple bundles, and the right bundles are automatically loaded
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
interface RouteObj {
|
|
10
|
+
path: string;
|
|
11
|
+
component?: React.LazyExoticComponent<() => JSX.Element>;
|
|
12
|
+
render?: () => JSX.Element;
|
|
13
|
+
requireAuth?: boolean;
|
|
14
|
+
excludeFromMenu?: boolean;
|
|
15
|
+
label?: string;
|
|
16
|
+
}
|
|
17
|
+
export const ROUTES: {[key: string]: RouteObj} = {
|
|
9
18
|
index: {
|
|
10
19
|
path: '/',
|
|
11
20
|
component: lazy(() => import('./pages/Home' /* webpackPrefetch: true */)),
|
|
12
|
-
|
|
13
|
-
label:"Home",
|
|
21
|
+
label: 'Home',
|
|
14
22
|
},
|
|
15
23
|
page1: {
|
|
16
24
|
path: '/page1',
|
|
17
25
|
component: lazy(() => import('./pages/Page1' /* webpackPrefetch: true */)),
|
|
18
|
-
label:
|
|
26
|
+
label: 'Protected page',
|
|
27
|
+
requireAuth: true,
|
|
28
|
+
},
|
|
29
|
+
signin: {
|
|
30
|
+
path: '/signin',
|
|
31
|
+
component: lazy(() => import('./pages/Signin' /* webpackPrefetch: true */)),
|
|
32
|
+
label: 'Sign In',
|
|
33
|
+
excludeFromMenu: true,
|
|
19
34
|
},
|
|
20
35
|
};
|
|
21
36
|
|
|
@@ -25,18 +40,33 @@ export default function AppRoutes() {
|
|
|
25
40
|
{Object.keys(ROUTES).map((routeName) => {
|
|
26
41
|
const route = ROUTES[routeName];
|
|
27
42
|
const Component = route.component;
|
|
43
|
+
|
|
44
|
+
//if a route is marked as requireAuth, wrap it in the RequireAuth component and pass the signinRoute
|
|
45
|
+
const AuthGuard = route.requireAuth ? RequireAuth : React.Fragment;
|
|
46
|
+
const authProps = route.requireAuth
|
|
47
|
+
? {signinRoute: ROUTES.signin.path}
|
|
48
|
+
: {};
|
|
49
|
+
|
|
50
|
+
// define a render function that determines what to render based on the component and route.render
|
|
51
|
+
const renderRoute = () =>
|
|
52
|
+
// if a Component is defined, render it using JSX syntax (<Component />)
|
|
53
|
+
// if not, check if a route.render function is defined and call that render function if available.
|
|
54
|
+
// if neither Component nor route.render is defined, return null
|
|
55
|
+
Component ? <Component /> : route.render ? route.render() : null;
|
|
56
|
+
|
|
28
57
|
return (
|
|
29
58
|
<Route
|
|
30
59
|
key={route.path}
|
|
31
60
|
path={route.path}
|
|
32
61
|
element={
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
</
|
|
62
|
+
<AuthGuard {...authProps}>
|
|
63
|
+
<Suspense fallback={<Spinner />}>{renderRoute()}</Suspense>
|
|
64
|
+
</AuthGuard>
|
|
36
65
|
}
|
|
37
66
|
/>
|
|
38
67
|
);
|
|
39
68
|
})}
|
|
69
|
+
<Route path="*" element={<PageNotFound />} />
|
|
40
70
|
</Routes>
|
|
41
71
|
);
|
|
42
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lincd-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.42",
|
|
4
4
|
"description": "Command line tools for the lincd.js library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"grunt-ts": "^6.0.0-beta.22",
|
|
59
59
|
"grunt-webpack": "^5.0.0",
|
|
60
60
|
"license-info-webpack-plugin": "^3.0.0",
|
|
61
|
-
"lincd": "0.5
|
|
61
|
+
"lincd": "^0.5",
|
|
62
62
|
"lincd-jsonld": "^0.1.22",
|
|
63
63
|
"lincd-modules": "^0.1",
|
|
64
64
|
"load-grunt-tasks": "^5.1.0",
|