Skip to content

Add "Back to documentation" link in 404 page#1020

Open
VictorPuga wants to merge 4 commits into
swiftlang:mainfrom
victorpuga-forks:404-link
Open

Add "Back to documentation" link in 404 page#1020
VictorPuga wants to merge 4 commits into
swiftlang:mainfrom
victorpuga-forks:404-link

Conversation

@VictorPuga

@VictorPuga VictorPuga commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a conditional "Back to Documentation" link to the 404 (Not Found) page that intelligently directs users to the first available module in the documentation. The implementation fetches the index data on page load and extracts the first module; if found, a link to that module is displayed. If no module is found or the fetch fails, the link is not rendered. Translations are provided for en-US, ja-JP, zh-CN, ko-KR, de-DE, es-419, fr-FR, it-IT, and pt-BR locales.

Based on the forum thread: https://forums.swift.org/t/improving-the-user-experience-at-the-documentation-archive-index/86433

image

Dependencies

None.

Testing

  1. Navigate to a non-existent URL (e.g., http://localhost:8080/nonexistent-page).
  2. Verify that the 404 page displays with a "Back to Documentation" link below the error message.
  3. Click the link and verify it navigates to the first available module.

Checklist

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary (translations added; no other docs needed)

VictorPuga and others added 4 commits June 6, 2026 17:54
Extract the first module from interfaceLanguages in the index data and link to it on the NotFound page. Falls back to /documentation if no module is found or the index fetch fails. Includes translations for en-US, ja-JP, zh-CN, and ko-KR.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add the back-to-documentation string to de-DE, es-419, fr-FR, it-IT, and
pt-BR locale files to complete the translations for the 404 page link.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The link container now conditionally renders based on whether the
documentation path was successfully fetched, preventing broken links
when the index cannot be accessed.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Tests verify that the back link renders when a module is
available, handles missing modules, graceful error handling,
and correctly selects the first module across languages.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@VictorPuga VictorPuga changed the title 404 link Add "Back to documentation" link in 404 page Jun 7, 2026
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