Open this example in the interactive library
Source code
"use client";
// components/ReadingWidthQueryLinks.tsx
import { Suspense } from "react";
import Link from "next/link";
import { useSearchParams, usePathname } from "next/navigation";
function ReadingWidthQueryLinksContent() {
const path = usePathname();
const q = useSearchParams();
return (
<nav>
{["narrow", "wide"].map((w) => {
const p = new URLSearchParams(q);
p.set("width", w);
return (
<Link key={w} href={path + "?" + p} scroll={false}>
{w}{" "}
</Link>
);
})}
</nav>
);
}
export default function ReadingWidthQueryLinks() {
return (
<Suspense fallback={<span>Loading view…</span>}>
<ReadingWidthQueryLinksContent />
</Suspense>
);
}
