@vlian/router 1.0.6 → 1.0.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/provider/transform.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/provider/transform.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,WAAW,EAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,qBAAqB,GAAG;IAChC,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,YAAY,CAAA;CACtB,CAAA;AACD,MAAM,MAAM,sBAAsB,GAAG;IACjC,IAAI,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC;CAC9B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,QAAQ,qBAAqB,EAAE,YAAY,SAAS,EAAE,UAAU,sBAAsB;;;CAwNxH,CAAA"}
|
|
@@ -241,9 +241,9 @@ import React from "react";
|
|
|
241
241
|
import { useUpdateEffect } from "ahooks";
|
|
242
242
|
export var useRouterTransform = function(config, rootRoutes, options) {
|
|
243
243
|
var transformRouteToReactRoutes = /**
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
* 批量处理路由
|
|
245
|
+
* @param routes 路由组
|
|
246
|
+
*/ function transformRouteToReactRoutes(routes) {
|
|
247
247
|
return routes.flatMap(function(route) {
|
|
248
248
|
return transformRouteToReactRoute(route);
|
|
249
249
|
});
|
|
@@ -253,9 +253,9 @@ export var useRouterTransform = function(config, rootRoutes, options) {
|
|
|
253
253
|
var _React_useState = _sliced_to_array(React.useState([]), 2), routes = _React_useState[0], setRoutes = _React_useState[1];
|
|
254
254
|
var _React_useState1 = _sliced_to_array(React.useState(null), 2), routeObject = _React_useState1[0], setRoutesObject = _React_useState1[1];
|
|
255
255
|
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
* 处理单个路由
|
|
257
|
+
* @param route 路由
|
|
258
|
+
*/ function transformRouteToReactRoute(route) {
|
|
259
259
|
var _route_isGroup = route.isGroup, isGroup = _route_isGroup === void 0 ? false : _route_isGroup, _route_enableRedirection = route.enableRedirection, enableRedirection = _route_enableRedirection === void 0 ? false : _route_enableRedirection, name = route.name, path = route.path, handle = route.handle, children = route.children, page = route.page, layout = route.layout, loading = route.loading, errors = route.errors;
|
|
260
260
|
// 获取错误组件
|
|
261
261
|
function getErrorComponent() {
|
|
@@ -541,14 +541,25 @@ export var useRouterTransform = function(config, rootRoutes, options) {
|
|
|
541
541
|
void initRouter();
|
|
542
542
|
}, deps);
|
|
543
543
|
useUpdateEffect(function() {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
rootRoute.children =
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
]));
|
|
544
|
+
// const rootRoute: RouteItem = {
|
|
545
|
+
// ...rootRoutes
|
|
546
|
+
// }
|
|
547
|
+
// if (!rootRoute.children) {
|
|
548
|
+
// rootRoute.children = [];
|
|
549
|
+
// }
|
|
550
|
+
// rootRoute.children = [...(routes || []), ...(staticRoutes || [])];
|
|
551
|
+
var restansformatRoutes = transformRouteToReactRoutes(_to_consumable_array(routes || []).concat(_to_consumable_array(staticRoutes || [])));
|
|
552
|
+
var rootPath = rootRoutes.path || '/';
|
|
553
|
+
var newRoutes = [
|
|
554
|
+
{
|
|
555
|
+
element: /*#__PURE__*/ React.createElement(Navigate, {
|
|
556
|
+
to: rootPath,
|
|
557
|
+
replace: true
|
|
558
|
+
}),
|
|
559
|
+
children: restansformatRoutes
|
|
560
|
+
}
|
|
561
|
+
];
|
|
562
|
+
setRoutesObject(newRoutes);
|
|
552
563
|
}, [
|
|
553
564
|
JSON.stringify(routes)
|
|
554
565
|
]);
|