UNPKG

sharyn

Version:

Combines all the other packages under one.

56 lines (45 loc) 1.79 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectWithoutProperties")); var _objectSpread2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/objectSpread")); var _reactRouterDom = require("react-router-dom"); var _loggedFilter = _interopRequireDefault(require("./logged-filter")); /* eslint-disable import/no-extraneous-dependencies */ var findMatch = function findMatch(routes, pathname, isLoggedIn) { var routesWithPlainPaths = routes.map(function (r) { return (0, _objectSpread2.default)({}, r, { path: typeof r.path === 'function' ? r.path() : r.path }); }); var accessibleRoutes = routesWithPlainPaths.filter(function (r) { return (0, _loggedFilter.default)(r, isLoggedIn); }); var notFoundRoute = accessibleRoutes.find(function (_ref) { var path = _ref.path; return !path; }); if (!notFoundRoute) { throw Error('You need a route without path to render a 404 page'); } var match; var activeRoute = accessibleRoutes.find(function (route) { match = (0, _reactRouterDom.matchPath)(pathname, route); return match; }) || notFoundRoute; var path = activeRoute.path, exact = activeRoute.exact, route = (0, _objectWithoutProperties2.default)(activeRoute, ["path", "exact"]); // Removing these properties from route return { match: match, route: route, routesWithPlainPaths: routesWithPlainPaths, accessibleRoutes: accessibleRoutes, notFoundRoute: notFoundRoute }; }; var _default = findMatch; exports.default = _default;