Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Update navigation so query params are passed over #760

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions docs/src/components/Layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ import { Logo } from '@/components/Logo';
import { FrameworkChooser } from './FrameworkChooser';

const NavLink = ({ href, children, isExternal = false }) => {
const router = useRouter();
const isCurrent = router.pathname.startsWith(href);
const { pathname, query } = useRouter();
const isCurrent = pathname.startsWith(href) && href !== '/';
const className = `docs-nav-link ${isCurrent ? 'current' : ''}`;

if (isExternal) {
return (
<Link isExternal className={className}>
<Link isExternal href={href} className={className}>
{children}
</Link>
);
}
return (
<NextLink href={href}>
<NextLink href={{ pathname: href, query }}>
<a className={className}>{children}</a>
</NextLink>
);
Expand Down Expand Up @@ -75,12 +75,12 @@ export const Header = ({ platform, colorMode, setColorMode }) => {
<Button className="docs-header-menu-button" size="small">
<IconMenu />
</Button>
<NextLink href="/">
<NavLink href="/">
<a className="docs-logo-link">
<VisuallyHidden>Amplify UI Home</VisuallyHidden>
<Logo />
</a>
</NextLink>
</NavLink>

<Flex as="nav" className="docs-nav" alignItems="center" gap="0">
<NavLink href="/getting-started/installation">
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/Layout/SecondaryNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const NavLinks = ({ items }: { items: ComponentNavItem[] }) => (
);

const NavLink = ({ href, children }) => {
const { pathname } = useRouter();
const { pathname, query } = useRouter();
const isCurrent = pathname === href;

return (
<Link href={href}>
<Link href={{ pathname: href, query }}>
<a className={`docs-secondary-nav-link ${isCurrent ? 'current' : ''}`}>
{children}
</a>
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/components/ComponentsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
navigationComponents,
utilityComponents,
} from '@/data/links';
import { useRouter } from 'next/router';

const ComponentGrid = ({ components }) => {
const { query } = useRouter();
return (
<Grid templateColumns="1fr 1fr" gap="var(--amplify-space-large)">
{components.map(({ href, label, body }) => (
<Link href={href} key={href}>
<Link href={{ pathname: href, query }} key={href}>
<Card className="docs-component-card" variation="elevated">
<Heading level={4}>{label}</Heading>
<div className="docs-component-card-contents">{body}</div>
Expand Down