@xfe-repo/web-router 1.0.1 → 1.0.3
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -12
- package/dist/index.mjs +2 -6
- package/package.json +10 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { History } from 'history';
|
|
2
2
|
import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
3
3
|
import { ParsedQuery } from 'query-string';
|
|
4
|
+
import React, { ReactElement, ComponentType } from 'react';
|
|
4
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
5
6
|
export * from 'react-router-dom';
|
|
6
|
-
import React, { ReactElement, ComponentType } from 'react';
|
|
7
7
|
|
|
8
8
|
type PageComponent = LoadableComponent<any> & RegisterComponentStatic;
|
|
9
9
|
type RouteConfig = {
|
|
10
10
|
path: string;
|
|
11
11
|
Component: PageComponent;
|
|
12
12
|
};
|
|
13
|
-
declare const getRoutes: (pagesIndexPath: string[], getPageComponents: (path: string) => Promise<any
|
|
13
|
+
declare const getRoutes: (pagesIndexPath: string[], getPageComponents: (path: string) => Promise<any>, fallback?: ReactElement) => RouteConfig[];
|
|
14
14
|
|
|
15
15
|
type RouterProps = {
|
|
16
16
|
navigator: NavigatorType;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { History } from 'history';
|
|
2
2
|
import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
3
3
|
import { ParsedQuery } from 'query-string';
|
|
4
|
+
import React, { ReactElement, ComponentType } from 'react';
|
|
4
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
5
6
|
export * from 'react-router-dom';
|
|
6
|
-
import React, { ReactElement, ComponentType } from 'react';
|
|
7
7
|
|
|
8
8
|
type PageComponent = LoadableComponent<any> & RegisterComponentStatic;
|
|
9
9
|
type RouteConfig = {
|
|
10
10
|
path: string;
|
|
11
11
|
Component: PageComponent;
|
|
12
12
|
};
|
|
13
|
-
declare const getRoutes: (pagesIndexPath: string[], getPageComponents: (path: string) => Promise<any
|
|
13
|
+
declare const getRoutes: (pagesIndexPath: string[], getPageComponents: (path: string) => Promise<any>, fallback?: ReactElement) => RouteConfig[];
|
|
14
14
|
|
|
15
15
|
type RouterProps = {
|
|
16
16
|
navigator: NavigatorType;
|
package/dist/index.js
CHANGED
|
@@ -287,10 +287,8 @@ var import_react_router_dom3 = require("react-router-dom");
|
|
|
287
287
|
var import_query_string = __toESM(require("query-string"));
|
|
288
288
|
__reExport(src_exports, require("react-router-dom"), module.exports);
|
|
289
289
|
// src/routes.ts
|
|
290
|
-
var import_react = require("react");
|
|
291
290
|
var import_component = __toESM(require("@loadable/component"));
|
|
292
|
-
var
|
|
293
|
-
var getRoutes = function(pagesIndexPath, getPageComponents) {
|
|
291
|
+
var getRoutes = function(pagesIndexPath, getPageComponents, fallback) {
|
|
294
292
|
var routes = [];
|
|
295
293
|
pagesIndexPath.forEach(function(pageIndexPath) {
|
|
296
294
|
if (pageIndexPath.startsWith("./")) return;
|
|
@@ -299,9 +297,7 @@ var getRoutes = function(pagesIndexPath, getPageComponents) {
|
|
|
299
297
|
var pageComponent = (0, import_component.default)(function() {
|
|
300
298
|
return getPageComponents(pageRelativePath);
|
|
301
299
|
}, {
|
|
302
|
-
fallback:
|
|
303
|
-
loading: true
|
|
304
|
-
})
|
|
300
|
+
fallback: fallback
|
|
305
301
|
});
|
|
306
302
|
var routerPath = "/".concat(pageRelativePath);
|
|
307
303
|
if (routerPath === "/home" || routerPath === "/index") routerPath = "/";
|
|
@@ -314,16 +310,16 @@ var getRoutes = function(pagesIndexPath, getPageComponents) {
|
|
|
314
310
|
return routes;
|
|
315
311
|
};
|
|
316
312
|
// src/Router.tsx
|
|
317
|
-
var
|
|
313
|
+
var import_react = require("react");
|
|
318
314
|
var import_react_router_dom = require("react-router-dom");
|
|
319
315
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
320
|
-
var Router = (0,
|
|
316
|
+
var Router = (0, import_react.memo)(function(props) {
|
|
321
317
|
var navigator = props.navigator, routes = props.routes, _props_basename = props.basename, basename = _props_basename === void 0 ? "/" : _props_basename, children = props.children, NotFoundPageComponent = props.NotFoundPageComponent;
|
|
322
|
-
var _ref = _sliced_to_array((0,
|
|
318
|
+
var _ref = _sliced_to_array((0, import_react.useState)({
|
|
323
319
|
action: navigator.action,
|
|
324
320
|
location: navigator.location
|
|
325
321
|
}), 2), navigatorState = _ref[0], setNavigatorState = _ref[1];
|
|
326
|
-
(0,
|
|
322
|
+
(0, import_react.useEffect)(function() {
|
|
327
323
|
return navigator.listen(setNavigatorState);
|
|
328
324
|
}, [
|
|
329
325
|
navigator
|
|
@@ -355,12 +351,12 @@ var Router = (0, import_react2.memo)(function(props) {
|
|
|
355
351
|
});
|
|
356
352
|
});
|
|
357
353
|
// src/Link.tsx
|
|
358
|
-
var
|
|
354
|
+
var import_react2 = require("react");
|
|
359
355
|
var import_react_router_dom2 = require("react-router-dom");
|
|
360
356
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
361
357
|
var Link = function(props) {
|
|
362
358
|
var to = props.to, children = props.children, reLaunch = props.reLaunch, preload = props.preload, replace = props.replace, className = props.className;
|
|
363
|
-
var _navigator2 = (0,
|
|
359
|
+
var _navigator2 = (0, import_react2.useMemo)(function() {
|
|
364
360
|
return getClientNavigator();
|
|
365
361
|
}, []);
|
|
366
362
|
if (/http(s)?:\/{2}/.test(to)) {
|
package/dist/index.mjs
CHANGED
|
@@ -6,19 +6,15 @@ import queryString from "query-string";
|
|
|
6
6
|
export * from "react-router-dom";
|
|
7
7
|
|
|
8
8
|
// src/routes.ts
|
|
9
|
-
import { createElement } from "react";
|
|
10
9
|
import loadable from "@loadable/component";
|
|
11
|
-
|
|
12
|
-
var getRoutes = (pagesIndexPath, getPageComponents) => {
|
|
10
|
+
var getRoutes = (pagesIndexPath, getPageComponents, fallback) => {
|
|
13
11
|
const routes = [];
|
|
14
12
|
pagesIndexPath.forEach((pageIndexPath) => {
|
|
15
13
|
if (pageIndexPath.startsWith("./"))
|
|
16
14
|
return;
|
|
17
15
|
const regExpResult = pageIndexPath.match(/(?<=pages\/).*(?=\/index.(?:tsx|js))/);
|
|
18
16
|
const pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
|
|
19
|
-
const pageComponent = loadable(() => getPageComponents(pageRelativePath), {
|
|
20
|
-
fallback: createElement(Loading, { loading: true })
|
|
21
|
-
});
|
|
17
|
+
const pageComponent = loadable(() => getPageComponents(pageRelativePath), { fallback });
|
|
22
18
|
let routerPath = `/${pageRelativePath}`;
|
|
23
19
|
if (routerPath === "/home" || routerPath === "/index")
|
|
24
20
|
routerPath = "/";
|
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"import": {
|
|
8
8
|
"types": "./dist/index.d.mts",
|
|
9
|
-
"
|
|
9
|
+
"default": "./dist/index.mjs"
|
|
10
10
|
},
|
|
11
11
|
"require": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
-
"default":
|
|
15
|
+
"default": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
@@ -22,16 +25,15 @@
|
|
|
22
25
|
"@loadable/component": "^5.15.3",
|
|
23
26
|
"history": "^5.3.0",
|
|
24
27
|
"query-string": "^7.1.3",
|
|
25
|
-
"react-router-dom": "^6.11.1"
|
|
26
|
-
"@xfe-repo/web-components": "1.0.1"
|
|
28
|
+
"react-router-dom": "^6.11.1"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
31
|
"@types/loadable__component": "^5.13.8",
|
|
30
32
|
"@types/node": "^20.10.4",
|
|
31
33
|
"@types/react": "^18.2.0",
|
|
32
|
-
"@xfe-repo/
|
|
33
|
-
"@xfe-repo/eslint-config": "0.0.
|
|
34
|
-
"@xfe-repo/
|
|
34
|
+
"@xfe-repo/web-register": "1.0.3",
|
|
35
|
+
"@xfe-repo/eslint-config": "0.0.2",
|
|
36
|
+
"@xfe-repo/typescript-config": "0.0.3"
|
|
35
37
|
},
|
|
36
38
|
"scripts": {
|
|
37
39
|
"build": "tsup",
|