Skip to content

Conversation

@gbarros
Copy link
Contributor

@gbarros gbarros commented Dec 9, 2025

This pull request introduces support for custom redirects in the Next.js configuration by reading from a new redirects.json file. It also makes minor adjustments to the Next.js export options. The most important changes are grouped below:

Redirects feature:

  • Added an asynchronous redirects() function to next.config.mjs that loads redirect rules from the new redirects.json file, enabling centralized management of redirects.
  • Created the redirects.json file, which contains a list of permanent redirect mappings for various routes.

Configuration updates:

  • Removed the output: 'export' option from the Next.js configuration, possibly to improve compatibility with the new redirects setup.
  • Added imports for Node.js fs and path modules in next.config.mjs to support reading the redirects file.

@gbarros gbarros requested a review from jcstein December 9, 2025 17:22
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gbarros, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the management of documentation redirects within the Next.js application. It establishes a centralized "redirects.json" file to define permanent URL mappings, ensuring that users accessing old or deprecated paths are seamlessly guided to the correct, updated content. This enhancement improves navigation, maintains link integrity, and supports better SEO for the documentation site.

Highlights

  • Custom Redirects Implementation: Introduced a new system for managing custom redirects in Next.js by adding an asynchronous "redirects()" function to "next.config.mjs" that reads rules from a dedicated "redirects.json" file.
  • Next.js Configuration Adjustment: The "output: 'export'" option was removed from the Next.js configuration, and Node.js "fs" and "path" modules were imported to support file system operations for the new redirect functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@jcstein
Copy link
Member

jcstein commented Dec 9, 2025

i wonder...if there's a way we can export this to work with static site 🤔

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a redirect mechanism by reading from a redirects.json file, which is a great way to manage redirects centrally. The implementation in next.config.mjs is mostly correct, but I've suggested an improvement to use asynchronous file reading and refine the error handling. This will make the build process more robust and non-blocking. The rest of the changes, including the new redirects.json file and the removal of output: 'export', look good and are consistent with the goal of enabling server-side redirects in Next.js.

Comment on lines 41 to 50
async redirects() {
try {
const redirectsPath = path.join(process.cwd(), 'redirects.json')
const redirectsData = fs.readFileSync(redirectsPath, 'utf8')
return JSON.parse(redirectsData)
} catch (error) {
console.error('Error reading redirects.json:', error)
return []
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation can be improved in two ways:

  1. Use asynchronous file reading: Since the redirects function is async, it's best practice to use the asynchronous fs.promises.readFile instead of the synchronous fs.readFileSync to avoid blocking the event loop during the build process.
  2. Improve error handling: The current catch block logs an error even if redirects.json is simply not found. It's better to handle the ENOENT (file not found) error code gracefully and only log other unexpected errors (like JSON parsing errors).
  async redirects() {
    try {
      const redirectsPath = path.join(process.cwd(), 'redirects.json');
      const redirectsData = await fs.promises.readFile(redirectsPath, 'utf8');
      return JSON.parse(redirectsData);
    } catch (error) {
      if (error.code === 'ENOENT') {
        // It's fine if the redirects file doesn't exist, just return an empty array.
        return [];
      }
      // For other errors (e.g., invalid JSON), log it and return an empty array.
      console.error('Error reading or parsing redirects.json:', error);
      return [];
    }
  }

Copy link
Member

@jcstein jcstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jcstein
Copy link
Member

jcstein commented Dec 9, 2025

@gbarros gbarros merged commit 5690e4e into docs-glow-up Dec 9, 2025
3 checks passed
@gbarros gbarros deleted the gb/redirects branch December 9, 2025 20:17
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.

3 participants