Makes the first render match the prerendered HTML
Search values, the 404 buttons and the footer year now apply after hydration. The e-mail address stays out of the HTML behind a placeholder, and all review texts are in the page, so crawlers can read them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,10 @@ import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import MobileNavGroup from './MobileNavGroup';
|
||||
|
||||
// Exact, like the submenu: no link counts as current on an unknown URL
|
||||
// (BR-404-05)
|
||||
const exactActive = { exact: true, includeSearch: false } as const;
|
||||
|
||||
type MobileNavProps = {
|
||||
id: string;
|
||||
open: boolean;
|
||||
@@ -93,6 +97,7 @@ export default function MobileNav({
|
||||
) : (
|
||||
<RouterLink
|
||||
to={item.to}
|
||||
activeOptions={exactActive}
|
||||
onClick={() =>
|
||||
dispatch({ type: 'linkChosen' })
|
||||
}
|
||||
|
||||
@@ -282,3 +282,44 @@ describe('NavigationBar current page', () => {
|
||||
expect(parent).not.toHaveAttribute('aria-current');
|
||||
});
|
||||
});
|
||||
|
||||
// The 404 page is prerendered for /404, so on an unknown URL no link may count
|
||||
// as current in the browser either, also not through the router's fuzzy
|
||||
// matching of a sub-path (BR-404-05)
|
||||
describe('NavigationBar and the current page', () => {
|
||||
const desktopLinks = () =>
|
||||
[
|
||||
...screen
|
||||
.getByRole('navigation', { name: 'Hoofdmenu' })
|
||||
.querySelectorAll('a'),
|
||||
].filter((link) => !panel()?.contains(link));
|
||||
const mobileLinks = () => [
|
||||
...document.getElementById('mobile-nav')!.querySelectorAll('a'),
|
||||
];
|
||||
const currentOf = (links: HTMLElement[]) =>
|
||||
links
|
||||
.filter((link) => link.getAttribute('aria-current') === 'page')
|
||||
.map((link) => link.textContent);
|
||||
|
||||
it.each(['/over-mij/x', '/portfolio/x', '/contact/x', '/onbekend'])(
|
||||
'marks no link as current on the unknown URL %s',
|
||||
async (path) => {
|
||||
await renderBar(path);
|
||||
expect(currentOf(desktopLinks())).toEqual([]);
|
||||
expect(currentOf(mobileLinks())).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
['/over-mij', 'Over mij'],
|
||||
['/portfolio?shoot=gezin', 'Portfolio'],
|
||||
['/contact?pakket=gezin', 'Contact'],
|
||||
])(
|
||||
'marks the page itself on %s, also with a search',
|
||||
async (path, name) => {
|
||||
await renderBar(path);
|
||||
expect(currentOf(desktopLinks())).toEqual([name]);
|
||||
expect(currentOf(mobileLinks())).toEqual([name]);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -24,6 +24,10 @@ import logoDark from '../../assets/logo-dark.png';
|
||||
// Het item met een submenu: bepaalt of het mobiele menu open start in een sectie
|
||||
const parentItem = mainNav.find(hasChildren);
|
||||
|
||||
// Exact: on an unknown URL (the prerendered 404 page) no link may count as
|
||||
// current, while the router would match /over-mij/x to Over mij (BR-404-05)
|
||||
const exactActive = { exact: true, includeSearch: false } as const;
|
||||
|
||||
export default function NavigationBar() {
|
||||
// Eén reducer voor het mobiele menu, de groep en het desktop-submenu, zodat
|
||||
// ze elkaar niet tegenspreken
|
||||
@@ -161,7 +165,10 @@ export default function NavigationBar() {
|
||||
dispatch={dispatch}
|
||||
/>
|
||||
) : (
|
||||
<NavLink to={item.to}>
|
||||
<NavLink
|
||||
to={item.to}
|
||||
activeOptions={exactActive}
|
||||
>
|
||||
{item.label}
|
||||
</NavLink>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user