( vnode: VNode, pathname: string, search?: string, )
| 80 | * Note: This function is used both on the server and the client |
| 81 | */ |
| 82 | export function setActiveUrl( |
| 83 | vnode: VNode, |
| 84 | pathname: string, |
| 85 | search?: string, |
| 86 | ): void { |
| 87 | const props = vnode.props as Record<string, unknown>; |
| 88 | const hrefProp = props.href; |
| 89 | if (typeof hrefProp === "string" && hrefProp.startsWith("/")) { |
| 90 | // Don't override aria-current if it's already set by the user |
| 91 | if (props["aria-current"] !== undefined) return; |
| 92 | |
| 93 | const match = matchesUrl(pathname, hrefProp, search); |
| 94 | if (match === UrlMatchKind.Current) { |
| 95 | props[DATA_CURRENT] = "true"; |
| 96 | props["aria-current"] = "page"; |
| 97 | } else if (match === UrlMatchKind.Ancestor) { |
| 98 | props[DATA_ANCESTOR] = "true"; |
| 99 | props["aria-current"] = "true"; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | export const enum PartialMode { |
| 105 | Replace, |
no test coverage detected