Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
29 lines
768 B
Plaintext
29 lines
768 B
Plaintext
import { pathToRegexp } from 'path-to-regexp';
|
|
export const isPathMatchingRoute = ({
|
|
currentRoute,
|
|
exact,
|
|
path: viewPath,
|
|
sensitive,
|
|
strict
|
|
}) => {
|
|
// if no path is defined, we cannot match it so return false early
|
|
if (!viewPath) {
|
|
return false;
|
|
}
|
|
const keys = [];
|
|
// run the view path through `pathToRegexp` to resolve any dynamic segments
|
|
// i.e. `/admin/custom-view/:id` -> `/admin/custom-view/123`
|
|
const regex = pathToRegexp(viewPath, keys, {
|
|
sensitive,
|
|
strict
|
|
});
|
|
const match = regex.exec(currentRoute);
|
|
const viewRoute = match?.[0] || viewPath;
|
|
if (exact) {
|
|
return currentRoute === viewRoute;
|
|
}
|
|
if (!exact) {
|
|
return viewRoute.startsWith(currentRoute);
|
|
}
|
|
};
|
|
//# sourceMappingURL=isPathMatchingRoute.js.map |