Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@umijs/route-utils
Advanced tools
@umijs/route-utils is a utility library for managing and manipulating routes in UmiJS applications. It provides a set of functions to handle route configurations, flatten nested routes, and match routes based on paths.
Flatten Nested Routes
This feature allows you to flatten nested route configurations into a single-level array. This can be useful for simplifying route management and ensuring all routes are easily accessible.
const { flattenRoutes } = require('@umijs/route-utils');
const nestedRoutes = [
{
path: '/',
routes: [
{ path: '/home', component: 'Home' },
{ path: '/about', component: 'About' }
]
}
];
const flatRoutes = flattenRoutes(nestedRoutes);
console.log(flatRoutes);
Match Routes
This feature allows you to match a given path against a set of routes and retrieve the matched route(s). This is useful for route validation and dynamic route handling.
const { matchRoutes } = require('@umijs/route-utils');
const routes = [
{ path: '/home', component: 'Home' },
{ path: '/about', component: 'About' }
];
const matchedRoutes = matchRoutes(routes, '/home');
console.log(matchedRoutes);
Generate Route Paths
This feature allows you to generate a path string from a path template and parameters. It is useful for creating dynamic URLs based on route parameters.
const { generatePath } = require('@umijs/route-utils');
const pathTemplate = '/user/:id';
const path = generatePath(pathTemplate, { id: 123 });
console.log(path);
React Router is a popular library for routing in React applications. It provides similar functionalities such as route matching and path generation, but it is more comprehensive and tightly integrated with React.
path-to-regexp is a utility for matching and parsing URL paths. It provides similar path matching and generation capabilities but is more low-level and not specifically tied to any framework.
route-parser is a lightweight library for parsing and generating URL routes. It offers similar functionalities for route matching and path generation but is simpler and more focused on basic route parsing.
# npm
npm i @umijs/route-utils --save
## yarn
yarn add @umijs/route-utils
import { transformRoute, getMatchMenu } from '@umijs/route-utils';
const routes = [
{
path: '/welcome',
name: 'welcome',
},
{
path: '/admin',
name: 'admin',
access: 'canAdmin',
},
{
name: 'list.table-list',
path: '/list',
},
];
const { menuData, breadcrumb } = transformRoute(routes);
console.log(menuData[0].name); // welcome
console.log(breadcrumb.get('/welcome').name); // welcome
import { MenuDataItem } from '@umijs/route-utils';
export interface MenuDataItem {
routes?: MenuDataItem[];
hideChildrenInMenu?: boolean;
hideInMenu?: boolean;
icon?: React.ReactNode;
locale?: string | false;
name?: string;
key?: string;
pro_layout_parentKeys?: string[];
path?: string;
[key: string]: any;
}
MIT
FAQs
Quickly process the routing of umi
We found that @umijs/route-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.