@zubyjs/react 1.0.33 → 1.0.35
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/package.json +1 -1
- package/router.js +9 -4
- package/templates/error.d.ts +4 -1
- package/templates/error.js +3 -3
package/package.json
CHANGED
package/router.js
CHANGED
|
@@ -10,17 +10,18 @@ let errors;
|
|
|
10
10
|
* Zuby's Router component provides support for file-system based routing.
|
|
11
11
|
*/
|
|
12
12
|
export default function Router({ context }) {
|
|
13
|
+
const isProduction = import.meta?.env?.MODE === 'production';
|
|
13
14
|
const loadTemplates = (templates) => templates?.map((pageTemplate) => ({
|
|
14
15
|
...pageTemplate,
|
|
15
16
|
component: lazy(pageTemplate.component),
|
|
16
17
|
})) || [];
|
|
17
|
-
if (!pages) {
|
|
18
|
+
if (!pages || !isProduction) {
|
|
18
19
|
pages = loadTemplates(context.templates?.pages);
|
|
19
20
|
}
|
|
20
|
-
if (!apps) {
|
|
21
|
+
if (!apps || !isProduction) {
|
|
21
22
|
apps = loadTemplates(context.templates?.apps);
|
|
22
23
|
}
|
|
23
|
-
if (!errors) {
|
|
24
|
+
if (!errors || !isProduction) {
|
|
24
25
|
errors = loadTemplates(context.templates?.errors);
|
|
25
26
|
}
|
|
26
27
|
const app = apps.find(({ pathRegex }) => {
|
|
@@ -29,7 +30,11 @@ export default function Router({ context }) {
|
|
|
29
30
|
const error = errors.find(({ pathRegex }) => {
|
|
30
31
|
return pathRegex.test(context.url.pathname ?? '');
|
|
31
32
|
});
|
|
32
|
-
const
|
|
33
|
+
const routes = [
|
|
34
|
+
...pages.map((page) => (_jsx(WouterRoute, { path: page.path, children: _jsx(page.component, { context: context }) }, page.path))),
|
|
35
|
+
_jsx(WouterRoute, { children: error?.component && (_jsx(error.component, { context: context, statusCode: (context.statusCode = 404), message: 'Page was not found' })) }, "error"),
|
|
36
|
+
];
|
|
37
|
+
const page = _jsx(WouterSwitch, { children: routes });
|
|
33
38
|
return (_jsx(WouterRouter, { ssrPath: context.url.pathname, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: createElement(app?.component, {
|
|
34
39
|
children: page,
|
|
35
40
|
}) }) }));
|
package/templates/error.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
export default function Error({
|
|
2
|
+
export default function Error({ statusCode, message, }: PropsWithChildren<{
|
|
3
|
+
statusCode: number;
|
|
4
|
+
message: string;
|
|
5
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
package/templates/error.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function Error({
|
|
3
|
-
return _jsx(
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export default function Error({ statusCode, message, }) {
|
|
3
|
+
return (_jsxs("div", { children: [_jsx("h1", { children: statusCode }), _jsx("p", { children: message })] }));
|
|
4
4
|
}
|