[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Proposed fix for Vercel config router issue 15031 regarding route rewrites

12 views · 0 likes · 1 post


LatentBass (@ruilopes-5761) · 2026-03-23

Hi! I took a look at issue 15031. Would the following be a proper fix? (plus updating the tests)


```diff
  ⎿  diff --git a/packages/config/src/router.ts b/packages/config/src/router.ts
     index 560152ba1..473f16761 100644
     --- a/packages/config/src/router.ts
     +++ b/packages/config/src/router.ts
     @@ -1,5 +1,4 @@
      import { cacheHeader } from 'pretty-cache-header';
     -import { sourceToRegex } from '@vercel/routing-utils';
      import { validateRegexPattern, parseCronExpression } from './utils/validation';
      import type {
        Condition,
     @@ -8,24 +7,6 @@ import type {
        Rewrite,
      } from './types';

     -/**
     - * Convert a destination string from path-to-regexp format to use capture group references.
     - * Replaces :paramName with $index based on the segments array.
     - */
     -function convertDestination(destination: string, segments: string[]): string {
     -  let result = destination;
     -  segments.forEach((segment, index) => {
     -    const patterns = [
     -      new RegExp(`:${segment}\\*`, 'g'),
     -      new RegExp(`:${segment}\\+`, 'g'),
     -      new RegExp(`:${segment}(?![a-zA-Z0-9_])`, 'g'),
     -    ];
     -    for (const pattern of patterns) {
     -      result = result.replace(pattern, `$${index + 1}`);
     -    }
     -  });
     -  return result;
     -}

      /**
       * Type utility to extract path parameter names from a route pattern string.
     @@ -777,13 +758,9 @@ export class Router {
              }
            }

     -      // Convert path-to-regexp patterns to regex for routes format
     -      const { src: regexSrc, segments } = sourceToRegex(source);
     -      const convertedDest = convertDestination(destination, segments);
     -
            const route: Route = {
     -        src: regexSrc,
     -        dest: convertedDest,
     +        source,
     +        destination,
              transforms,
            };
            if (has) route.has = has;
     @@ -936,13 +913,9 @@ export class Router {
              transforms.push(transform);
            }

     -      // Convert path-to-regexp patterns to regex for routes format
     -      const { src: regexSrc, segments } = sourceToRegex(source);
     -      const convertedDest = convertDestination(destination, segments);
     -
            const route: Route = {
     -        src: regexSrc,
     -        dest: convertedDest,
     +        source,
     +        destination,
              status: statusCode || (permanent ? 308 : 307),
              transforms,
            };


```