chore: fix the route tab regex error

This commit is contained in:
amlannandy 2025-07-03 08:33:14 +07:00
parent 5102cf2b7b
commit aaaad8e0a2

View File

@ -29,6 +29,11 @@ function RouteTab({
// Find the matching route for the current pathname
const currentRoute = routesWithParams.find((route) => {
try {
const routePattern = route.route.replace(/:(\w+)/g, '([^/]+)');
const regex = new RegExp(`^${routePattern}$`);
return regex.test(location.pathname);
} catch (error) {
const pathnameOnly = route.route.split('?')[0];
const routePattern = escapeRegExp(pathnameOnly).replace(
/\\:([a-zA-Z0-9_]+)/g,
@ -36,6 +41,7 @@ function RouteTab({
);
const regex = new RegExp(`^${routePattern}$`);
return regex.test(location.pathname);
}
});
const onChange = (activeRoute: string): void => {