Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions samples/hydrogen/src/components/NavBar/default.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildNodeUrl, getChildNodes, jahiaComponent } from "@jahia/javascript-modules-library";
import { getChildNodes, jahiaComponent, JLink } from "@jahia/javascript-modules-library";
import type { JCRNodeWrapper } from "org.jahia.services.content";
import classes from "./component.module.css";

Expand All @@ -11,24 +11,22 @@ jahiaComponent(
componentType: "view",
nodeType: "hydrogen:navBar",
displayName: "NavBar",
// JLink emits aria-current on the page being rendered, which is not part of the fragment
// cache key unless the view says so. Without this the nav would be cached once and replayed,
// marking the same entry current on every page.
properties: { "cache.mainResource": "true" },
},
(_, { renderContext, mainNode }) => (
(_, { renderContext }) => (
<nav className={classes.nav}>
<ul>
{getChildPages(renderContext.getSite()).map((page) => (
<li key={page.getPath()}>
<a href={buildNodeUrl(page)} aria-current={page === mainNode ? "page" : undefined}>
{page.getProperty("jcr:title").getString()}
</a>
{/* No children: the label comes from the page itself */}
<JLink node={page} />
<ul>
{getChildPages(page).map((page) => (
<li key={page.getPath()}>
<a
href={buildNodeUrl(page)}
aria-current={page === mainNode ? "page" : undefined}
>
{page.getProperty("jcr:title").getString()}
</a>
<JLink node={page} />
</li>
))}
</ul>
Expand Down
Loading