UNPKG

@snipsonian/redux-first-router

Version:

Redux-first-router snippets

32 lines (31 loc) 898 B
let allRoutes; export function registerRoutes(routes) { allRoutes = routes; } export function getRegisteredRoutes() { return allRoutes; } export function getRoute({ routeKey }) { return allRoutes[routeKey]; } export function getRoutePath({ routeKey }) { return getRoute({ routeKey }).path; } export function getRouteKeyByPath({ path }) { return getAllRouteKeys() .find((routeKey) => getRoute({ routeKey }).path === path); } export function doesRouteBelongToGroup({ routeKey, group }) { const route = getRoute({ routeKey }); if (!route || !route.groups) { return false; } return route.groups.indexOf(group) > -1; } export function getRouteKeysThatBelongToGroup({ group }) { return getAllRouteKeys() .filter((routeKey) => doesRouteBelongToGroup({ routeKey, group })); } function getAllRouteKeys() { return Object.keys(allRoutes); }