Skip to content

feat/site: Add navigation links on 404 page - #1887

Open
marcleblanc2 wants to merge 4 commits into
mainfrom
not-found-back-and-up-links
Open

feat/site: Add navigation links on 404 page#1887
marcleblanc2 wants to merge 4 commits into
mainfrom
not-found-back-and-up-links

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What

The 404 page only offered "Go back home". It now also shows, when applicable:

  • Go back to <path> — the docs page the user was on before this one
  • Go up to <path> — the closest ancestor of the requested URL that is a real docs page (preview pages excluded). Omitted when that ancestor is the root (the home link covers it) or is the same page as the back link.

Before

  • Only see a clickable link to the home page, which is almost never where I want to go
image

After

  • Also see a link back to the previous page I was on
  • If there's also a valid parent page, which is different than the previous page, then show that as an option as well (useful because we have so many broken links / redirects to old subpages, and the content's likely been moved to the parent page, or another page I can click to from the parent page)
image

@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 10, 2026 1:03am UTC

Request Review

@marcleblanc2 marcleblanc2 changed the title 404 page: link back to the referring page and up to the nearest existing ancestor 404 page: Link back to the referring page and up to the nearest existing ancestor Sep 9, 2026
@marcleblanc2 marcleblanc2 changed the title 404 page: Link back to the referring page and up to the nearest existing ancestor Link the 404 page back to the referring page and up to the nearest existing ancestor Sep 9, 2026
@marcleblanc2 marcleblanc2 changed the title Link the 404 page back to the referring page and up to the nearest existing ancestor feat/site: Improve 404 page with links back to the referring page and up to the nearest ancestor Sep 9, 2026
@marcleblanc2 marcleblanc2 changed the title feat/site: Improve 404 page with links back to the referring page and up to the nearest ancestor feat/site: Improve 404 page with links back to the previous page and up to the nearest ancestor Sep 9, 2026
@marcleblanc2
marcleblanc2 marked this pull request as ready for review September 9, 2026 10:28
@marcleblanc2 marcleblanc2 changed the title feat/site: Improve 404 page with links back to the previous page and up to the nearest ancestor feat/site: Improve 404 page with links Sep 10, 2026
@marcleblanc2 marcleblanc2 changed the title feat/site: Improve 404 page with links feat/site: Add navigation links on 404 page Sep 10, 2026
@marcleblanc2
marcleblanc2 marked this pull request as draft September 10, 2026 00:55
marcleblanc2 and others added 4 commits September 9, 2026 19:00
…ing ancestor

The 404 page only offered a link home. Now it also shows:

- "Go back to <path>" when document.referrer is on the same origin
- "Go up to <path>" for the closest ancestor of the requested URL that is
  a real docs page (preview pages excluded), when that is not the root

not-found.tsx stays a server component and passes the list of page paths
from contentlayer to a small client component, which resolves both links
after mount because the prerendered 404 page does not know the browser URL.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08450-afc0-7264-afde-d3e2a47be6d2
Co-authored-by: Amp <amp@ampcode.com>
…ent-side navigation

document.referrer only reflects the last full page load, so clicking a broken
<Link> inside the docs left the 404 page without a back link. A
PreviousPathnameProvider in the root layout (which React keeps mounted across
client-side navigations) now remembers the prior pathname; the 404 page prefers
it and falls back to a same-origin document.referrer on fresh loads.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08450-afc0-7264-afde-d3e2a47be6d2
Co-authored-by: Amp <amp@ampcode.com>
Editing the URL bar is a fresh load with no referrer, so the 404 page had
nothing to link back to. Persist the visited pathnames in sessionStorage
(per tab) so that case works too, and only offer "Go back" when the
previous pathname is a real page, since it may itself have been a 404.
@marcleblanc2
marcleblanc2 force-pushed the not-found-back-and-up-links branch from ccbe7a3 to 1041225 Compare September 10, 2026 01:00
@marcleblanc2
marcleblanc2 marked this pull request as ready for review September 10, 2026 01:11
@marcleblanc2
marcleblanc2 requested a review from a team September 10, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant