MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / convertRemixRouteIdToPath

Function convertRemixRouteIdToPath

packages/remix/src/utils/utils.ts:54–110  ·  view source on GitHub ↗
(routeId: string)

Source from the content-addressed store, hash-verified

52 * @internal
53 */
54export function convertRemixRouteIdToPath(routeId: string): string {
55 // Remove the "routes/" prefix if present
56 const path = routeId.replace(/^routes\//, '');
57
58 // Handle root index route
59 if (path === 'index' || path === '_index') {
60 return '/';
61 }
62
63 // Split by dots to get segments
64 const segments = path.split('.');
65 const pathSegments: string[] = [];
66
67 for (let i = 0; i < segments.length; i++) {
68 const segment = segments[i];
69
70 if (!segment) {
71 continue;
72 }
73
74 // Skip layout route segments (prefixed with _)
75 if (segment.startsWith('_') && segment !== '_index') {
76 continue;
77 }
78
79 // Handle '_index' segments at the end (always skip - indicates an index route)
80 if (segment === '_index' && i === segments.length - 1) {
81 continue;
82 }
83
84 // Handle 'index' segments at the end (skip only if there are path segments,
85 // otherwise root index is handled by the early return above)
86 if (segment === 'index' && i === segments.length - 1 && pathSegments.length > 0) {
87 continue;
88 }
89
90 // Handle splat routes (catch-all)
91 // Remix accesses splat params via params["*"] at runtime
92 if (segment === '$') {
93 pathSegments.push(':*');
94 continue;
95 }
96
97 // Handle dynamic segments (prefixed with $)
98 if (segment.startsWith('$')) {
99 const paramName = segment.substring(1);
100 pathSegments.push(`:${paramName}`);
101 } else if (segment !== 'index') {
102 // Static segment (skip remaining 'index' segments)
103 pathSegments.push(segment);
104 }
105 }
106
107 // Return with leading slash for consistency with client-side URL paths
108 const routePath = pathSegments.length > 0 ? `/${pathSegments.join('/')}` : '/';
109 return routePath;
110}
111

Callers 3

utils.test.tsFile · 0.90
getTransactionNameFunction · 0.85

Calls 2

replaceMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected