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

Enable client-side routing for all Markdown links #797

Merged
merged 1 commit into from
May 16, 2023
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: 10 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ import {
useRouteError,
} from '@remix-run/react'
import { ButtonGroup, GovBanner, GridContainer } from '@trussworks/react-uswds'
import type { ReactNode } from 'react'
import { type ReactNode, useRef } from 'react'
import TopBarProgress from 'react-topbar-progress-indicator'
import { useDelegatedAnchors } from 'remix-utils'
import { useSpinDelay } from 'spin-delay'

import { DevBanner } from './components/DevBanner'
Expand Down Expand Up @@ -207,6 +208,11 @@ function Progress() {
}

function Document({ children }: { children?: React.ReactNode }) {
// Use client-side routing for anchors in Markdown content.
// See https://github.com/remix-run/remix/discussions/6048.
const ref = useRef<HTMLElement | null>(null)
useDelegatedAnchors(ref)

return (
<html lang="en-US">
<head>
Expand All @@ -223,7 +229,9 @@ function Document({ children }: { children?: React.ReactNode }) {
<DevBanner />
<Header />
<NewsBanner message="GCN Circulars are now part of the new GCN!" />
<main id="main-content">{children}</main>
<main id="main-content" ref={ref}>
{children}
</main>
<Footer />
<ScrollRestoration />
<Scripts />
Expand Down
130 changes: 127 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"react-router": "^6.10.0",
"react-tag-autocomplete": "^7.0.0-rc.1",
"react-topbar-progress-indicator": "^4.1.1",
"remix-utils": "github:lpsinger/remix-utils#route-data-moved-npm-prepare",
"spin-delay": "^1.1.0",
"ts-dedent": "^2.2.0"
},
Expand Down