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