This commit is contained in:
27
node_modules/react-router/modules/generatePath.js
generated
vendored
Normal file
27
node_modules/react-router/modules/generatePath.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import pathToRegexp from "path-to-regexp";
|
||||
|
||||
const cache = {};
|
||||
const cacheLimit = 10000;
|
||||
let cacheCount = 0;
|
||||
|
||||
function compilePath(path) {
|
||||
if (cache[path]) return cache[path];
|
||||
|
||||
const generator = pathToRegexp.compile(path);
|
||||
|
||||
if (cacheCount < cacheLimit) {
|
||||
cache[path] = generator;
|
||||
cacheCount++;
|
||||
}
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public API for generating a URL pathname from a path and parameters.
|
||||
*/
|
||||
function generatePath(path = "/", params = {}) {
|
||||
return path === "/" ? path : compilePath(path)(params, { pretty: true });
|
||||
}
|
||||
|
||||
export default generatePath;
|
||||
Reference in New Issue
Block a user