mirror of
https://github.com/docmost/docmost.git
synced 2026-05-17 14:54:05 +08:00
17 lines
394 B
TypeScript
17 lines
394 B
TypeScript
import { useLocation } from 'react-router-dom';
|
|
|
|
export const useMatchPath = () => {
|
|
const location = useLocation();
|
|
|
|
const matchPath = (pattern) => {
|
|
const modifiedPattern = pattern
|
|
.replace(/:([^/]+)/g, '([^/]+)(?:/.*)?')
|
|
.replace(/\//g, '\\/');
|
|
|
|
const regex = new RegExp(`^${modifiedPattern}$`);
|
|
return regex.test(location.pathname);
|
|
};
|
|
|
|
return matchPath;
|
|
};
|