MCPcopy
hub / github.com/freshframework/fresh / setActiveUrl

Function setActiveUrl

packages/fresh/src/runtime/shared_internal.ts:82–102  ·  view source on GitHub ↗
(
  vnode: VNode,
  pathname: string,
  search?: string,
)

Source from the content-addressed store, hash-verified

80 * Note: This function is used both on the server and the client
81 */
82export 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
104export const enum PartialMode {
105 Replace,

Callers 1

preact_hooks.tsFile · 0.90

Calls 1

matchesUrlFunction · 0.85

Tested by

no test coverage detected