UNPKG

@macrof/shared

Version:

React MicroFrontend Shared, Typescript, Webpack 5, ModuleFederation

12 lines (11 loc) 1.07 kB
import React, { Fragment } from 'react'; import { Route, Routes, Navigate } from 'react-router-dom'; const CustomRouters = ({ routers }) => (React.createElement(Routes, null, routers.map((router, i) => { var _a; return router.isDefault ? (React.createElement(Route, { index: true, key: `_${Math.pow(i, 1)}_${router.path}`, path: router.path, element: router.component && React.createElement(router.component, null) })) : (React.createElement(Fragment, { key: `_${Math.pow(i, 1)}_${router.path}` }, React.createElement(Route, { path: router.path }, React.createElement(Route, { index: true, element: router.component && React.createElement(router.component, null) }), ((_a = router.child) === null || _a === void 0 ? void 0 : _a.length) && React.createElement(Route, { path: "*", element: React.createElement(CustomRouters, { routers: router.child }) })), React.createElement(Route, { index: true, path: "*", element: React.createElement(Navigate, { replace: true, to: "" }) }))); }))); export const MFRouters = CustomRouters;