detectRouteCollision() — astro Function Reference
Architecture documentation for the detectRouteCollision() function in create.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 6d3eab18_f149_cd0f_b9bf_e3324684390e["detectRouteCollision()"] a7eed989_9f2b_5163_ecdf_85920a8b973f["create.ts"] 6d3eab18_f149_cd0f_b9bf_e3324684390e -->|defined in| a7eed989_9f2b_5163_ecdf_85920a8b973f 980f5a1b_85ee_0217_7a04_888abfb8f70f["createRoutesList()"] 980f5a1b_85ee_0217_7a04_888abfb8f70f -->|calls| 6d3eab18_f149_cd0f_b9bf_e3324684390e b81576c5_5ca8_7f92_fc59_7489816844e2["isSemanticallyEqualSegment()"] 6d3eab18_f149_cd0f_b9bf_e3324684390e -->|calls| b81576c5_5ca8_7f92_fc59_7489816844e2 style 6d3eab18_f149_cd0f_b9bf_e3324684390e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/routing/manifest/create.ts lines 425–482
function detectRouteCollision(a: RouteData, b: RouteData, _config: AstroConfig, logger: Logger) {
if (a.type === 'fallback' || b.type === 'fallback') {
// If either route is a fallback route, they don't collide.
// Fallbacks are always added below other routes exactly to avoid collisions.
return;
}
if (
a.route === b.route &&
a.segments.every(isStaticSegment) &&
b.segments.every(isStaticSegment)
) {
// If both routes are the same and completely static they are guaranteed to collide
// such that one of them will never be matched.
logger.warn(
'router',
`The route "${a.route}" is defined in both "${a.component}" and "${b.component}". A static route cannot be defined more than once.`,
);
logger.warn(
'router',
'A collision will result in an hard error in following versions of Astro.',
);
return;
}
if (a.prerender || b.prerender) {
// If either route is prerendered, it is impossible to know if they collide
// at this stage because it depends on the parameters returned by `getStaticPaths`.
return;
}
if (a.segments.length !== b.segments.length) {
// If the routes have different number of segments, they cannot perfectly overlap
// each other, so a collision is either not guaranteed or may be intentional.
return;
}
// Routes have the same number of segments, can use either.
const segmentCount = a.segments.length;
for (let index = 0; index < segmentCount; index++) {
const segmentA = a.segments[index];
const segmentB = b.segments[index];
if (!isSemanticallyEqualSegment(segmentA, segmentB)) {
// If any segment is not semantically equal between the routes
// it is not certain that the routes collide.
return;
}
}
// Both routes are guaranteed to collide such that one will never be matched.
logger.warn(
'router',
`The route "${a.route}" is defined in both "${a.component}" and "${b.component}" using SSR mode. A dynamic SSR route cannot be defined more than once.`,
);
logger.warn('router', 'A collision will result in an hard error in following versions of Astro.');
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does detectRouteCollision() do?
detectRouteCollision() is a function in the astro codebase, defined in packages/astro/src/core/routing/manifest/create.ts.
Where is detectRouteCollision() defined?
detectRouteCollision() is defined in packages/astro/src/core/routing/manifest/create.ts at line 425.
What does detectRouteCollision() call?
detectRouteCollision() calls 1 function(s): isSemanticallyEqualSegment.
What calls detectRouteCollision()?
detectRouteCollision() is called by 1 function(s): createRoutesList.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free