@zubyjs/react 1.0.37 → 1.0.39

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/router.d.ts +4 -0
  3. package/router.js +11 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubyjs/react",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "Zuby.js JsxProvider for react",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/router.d.ts CHANGED
@@ -11,3 +11,7 @@ export declare function Page({ page, context }: {
11
11
  page: LazyTemplate;
12
12
  context: ZubyPageContext;
13
13
  }): import("react/jsx-runtime").JSX.Element;
14
+ export declare function Error({ error, context }: {
15
+ error: LazyTemplate;
16
+ context: ZubyPageContext;
17
+ }): import("react/jsx-runtime").JSX.Element;
package/router.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Router as WouterRouter, Route as WouterRoute, Switch as WouterSwitch } from 'wouter';
3
3
  export { useRoute, useRouter, useParams, useLocation, Link, Redirect, } from 'wouter';
4
+ import { useParams } from 'wouter';
4
5
  import { Suspense, lazy } from 'react';
5
6
  import { createElement } from 'react';
6
7
  import { useFetch } from './hooks/index.js';
@@ -33,7 +34,7 @@ export default function Router({ context }) {
33
34
  });
34
35
  const routes = [
35
36
  ...pages.map((page) => (_jsx(WouterRoute, { path: page.path, children: _jsx(Page, { context: context, page: page }) }, page.path))),
36
- _jsx(WouterRoute, { children: error?.component && (_jsx(error.component, { context: context, statusCode: (context.statusCode = 404), message: 'Page was not found' })) }, "error"),
37
+ _jsx(WouterRoute, { children: error?.component && _jsx(Error, { context: context, error: error }) }, "error"),
37
38
  ];
38
39
  const page = _jsx(WouterSwitch, { children: routes });
39
40
  return (_jsx(WouterRouter, { ssrPath: context.url.pathname, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: createElement(app?.component, {
@@ -41,8 +42,16 @@ export default function Router({ context }) {
41
42
  }) }) }));
42
43
  }
43
44
  export function Page({ page, context }) {
45
+ context.statusCode = 200;
46
+ context.params = useParams();
44
47
  if (typeof window !== 'undefined') {
45
- context.props = useFetch('/_props' + context.url.pathname);
48
+ context.props = useFetch(`/_props${context.url.pathname}`);
46
49
  }
47
50
  return _jsx(page.component, { context: context });
48
51
  }
52
+ export function Error({ error, context }) {
53
+ context.statusCode = 404;
54
+ context.params = useParams();
55
+ context.props = {};
56
+ return _jsx(error.component, { context: context, message: 'Page was not found' });
57
+ }