UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = exports.collectUniversalRoutes = void 0;
9
10var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
12var _lodash = require("lodash");
13
14var _flatten = _interopRequireDefault(require("lodash/flatten"));
15
16var collectUniversalRoutes = function collectUniversalRoutes(route) {
17 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
18 _ref$path = _ref.path,
19 parentPath = _ref$path === void 0 ? '' : _ref$path;
20
21 if (Array.isArray(route)) return (0, _flatten["default"])(route.map(collectUniversalRoutes));
22
23 if ((0, _lodash.isPlainObject)(route)) {
24 var path = [parentPath, route.path].join('#');
25 var children = route.children ? (0, _flatten["default"])(route.children.map(function (a) {
26 return collectUniversalRoutes(a, {
27 path: path
28 });
29 })) : [];
30 return [path].concat((0, _toConsumableArray2["default"])(children));
31 }
32
33 return [];
34};
35
36exports.collectUniversalRoutes = collectUniversalRoutes;
37var _default = collectUniversalRoutes;
38exports["default"] = _default;
39//# sourceMappingURL=collectUniversalRoutes.js.map
\No newline at end of file