Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Match a path section at its root and descendant boundaries
When matching or excluding a URL path section, handle the section root and slash-delimited descendants explicitly. A descendant-only prefix misses the root, while a raw prefix also matches unrelated sibling names.
Bad example
| 1 | export function isInSection(pathname: string, section: string): boolean { |
| 2 | return pathname.startsWith(`${section}/`); |
| 3 | } |
| 4 | // isInSection('/members', '/members') is false. |
Explanation (EN)
The root page is omitted from the exclusion even though its descendants are excluded.
Objašnjenje (HR)
Korijenska stranica odjeljka ostaje izvan iznimke iako su podstranice isključene.
Good example
| 1 | export function isInSection(pathname: string, section: string): boolean { |
| 2 | const path = pathname.replace(/\/+$/, '') || '/'; |
| 3 | const root = section.replace(/\/+$/, '') || '/'; |
| 4 | return path === root || (root !== '/' && path.startsWith(`${root}/`)); |
| 5 | } |
Explanation (EN)
Equality covers the root, the slash boundary covers descendants, and /membership does not match /members.
Objašnjenje (HR)
Jednakost pokriva korijen, kosa crta podstranice, a /membership se ne poklapa s /members.
Notes (EN)
Use parsed pathnames and check origin separately for absolute navigation URLs. Test the root, trailing slash, descendant and similarly prefixed sibling. Prefer an existing router matcher when available. In this helper the site root matches only itself.
Bilješke (HR)
Koristi parsirane putanje, a kod apsolutnih URL-ova zasebno provjeri origin. Pokrij korijen, završnu kosu crtu, podstranicu i slično imenovan susjedni odjeljak. Ako router već ima matcher, koristi njega. U ovom helperu korijen weba poklapa se samo sa sobom.
Exceptions / Tradeoffs (EN)
Exact-page matching and deliberately sitewide root matching are different contracts. This navigation helper is not a substitute for authorization or filesystem path containment.
Iznimke / Tradeoffi (HR)
Poklapanje samo jedne stranice i namjerno poklapanje cijelog weba imaju drukčiji ugovor. Ovaj navigacijski helper nije zamjena za autorizaciju ni provjeru putanja datotečnog sustava.