Pure helper die doel-URL bij product-wissel bepaalt; unit-tests dekken alle pad-gevallen. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
14 lines
479 B
TypeScript
14 lines
479 B
TypeScript
export function resolveProductSwitchTarget(
|
|
pathname: string,
|
|
newProductId: string,
|
|
): string | null {
|
|
const match = pathname.match(/^\/products\/([^/]+)(\/.*)?$/)
|
|
if (!match) return null
|
|
|
|
const rest = match[2] ?? ''
|
|
|
|
if (!rest || rest === '/') return `/products/${newProductId}`
|
|
if (rest.startsWith('/sprint')) return `/products/${newProductId}/sprint`
|
|
if (rest.startsWith('/solo')) return `/products/${newProductId}/solo`
|
|
return `/products/${newProductId}`
|
|
}
|