Skip to content

Conversation

@LuiGeeDev
Copy link

@LuiGeeDev LuiGeeDev commented Oct 15, 2025

I needed to set different titles for same page with different data and found that this can be done using the head(ctx) function.
It wasn’t clearly mentioned in the current docs, but my editor suggested the head(ctx) syntax, which worked as expected.
Since most other frameworks include a short explanation or example for this pattern, I thought it would be helpful to add a brief note here as well.

English is not my first language, so the added sentence and this description was refined with AI assistance — please feel free to adjust the wording if needed.

Summary by CodeRabbit

  • Documentation
    • Added a Route-level Document Head section to the React guide.
    • Shows how to use the route context inside the head function to customize titles and meta per route.
    • Includes an example of dynamic title/meta based on route data and illustrates RouteOptionsType head usage.
    • Clarifies required placement of the HeadContent component and links to head-method docs.

Added section on route-level document head management with example code.
@github-actions github-actions bot added the documentation Everything documentation related label Oct 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

Adds a Route-level Document Head section to the React guide showing how to use a route head function with the context object to set dynamic titles and meta tags from route data, links to the head method docs, shows RouteOptionsType head usage, and reiterates <HeadContent /> placement. No code or API changes.

Changes

Cohort / File(s) Summary
React Router Docs — Document Head
docs/router/framework/react/guide/document-head-management.md
Expanded documentation to add a route-level head function example using the route context for dynamic title/meta, link to the head method docs, show RouteOptionsType head usage, and remind to include <HeadContent />. No behavior/API changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

I twitch my whiskers at new lines of light,
Per-route titles hopping into sight 🐇,
Meta seeds scattered from data’s store,
<HeadContent /> snug behind the door.
Docs updated — I nibble, then delight.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely and accurately reflects the primary change by indicating the addition of documentation for route‐level head usage along with an example in the guides.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/router/framework/react/guide/document-head-management.md (1)

68-68: Use a descriptive, relative docs link

Per our docs guidelines, link text shouldn’t be “here” and links must stay within the docs tree. Please update the anchor text (e.g. “RouteOptionsType head method”) and link it relatively: ../api/router/RouteOptionsType#head-method.

As per coding guidelines

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 975e32f and 8c892e8.

📒 Files selected for processing (1)
  • docs/router/framework/react/guide/document-head-management.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use internal docs links relative to the docs/ folder (e.g., ./guide/data-loading)

Files:

  • docs/router/framework/react/guide/document-head-management.md
docs/{router,start}/**

📄 CodeRabbit inference engine (AGENTS.md)

Place router docs under docs/router/ and start framework docs under docs/start/

Files:

  • docs/router/framework/react/guide/document-head-management.md
🪛 LanguageTool
docs/router/framework/react/guide/document-head-management.md

[grammar] ~67-~67: There might be a mistake here.
Context: ... title or meta tags based on route data. You can find the full list of available ...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.18.1)
docs/router/framework/react/guide/document-head-management.md

68-68: Link text should be descriptive

(MD059, descriptive-link-text)

Comment on lines 71 to 87
export const Route = createRootRoute({
loader: async ({ params }) {
const id = params.id;
return await fetchPost({ id });
},
head: (context) => ({
meta: [
{
name: 'description',
content: context.loaderData.content.slice(0, 100),
},
{
title: context.loaderData.title,
},
],
}),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix the route example: createRootRoute has no params.id

createRootRoute never receives dynamic params, so params.id will always be undefined and the sample fetch call fails. Please switch the snippet to a parametrized route (e.g. createFileRoute('/posts/$postId')) and reference the actual param/key returned by the loader. That keeps the example accurate and prevents readers from copying a broken pattern.

🤖 Prompt for AI Agents
In docs/router/framework/react/guide/document-head-management.md around lines
71–87, the example uses createRootRoute and params.id (which is always
undefined); change the route to a parametrized route (e.g. use
createFileRoute('/posts/$postId') instead of createRootRoute), update the loader
to read the dynamic param from params.postId and pass that into fetchPost, and
keep the head accessor using the actual loader return shape (e.g.
context.loaderData.title and context.loaderData.content.slice(0,100)); this
ensures the example uses a route that receives params and references the correct
param key.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
docs/router/framework/react/guide/document-head-management.md (1)

65-88: Still need a parametrized route & correct param key

The snippet still reads params.id, but this route never defines an id param—createFileRoute must be given a parametrized path (e.g. /posts/$postId), and the loader should read params.postId. Without that, the fetch example keeps receiving undefined. Please update the example to declare the dynamic segment and use the actual param key returned by the loader.

🧹 Nitpick comments (1)
docs/router/framework/react/guide/document-head-management.md (1)

68-68: Use descriptive, relative link text

Docs lint flags the “here” link. Please switch to descriptive link text (e.g. “RouteOptionsType#head docs”) and make it relative to this guide, per docs linking guidelines (../api/router/RouteOptionsType#head-method).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c892e8 and 624c9e2.

📒 Files selected for processing (1)
  • docs/router/framework/react/guide/document-head-management.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use internal docs links relative to the docs/ folder (e.g., ./guide/data-loading)

Files:

  • docs/router/framework/react/guide/document-head-management.md
docs/{router,start}/**

📄 CodeRabbit inference engine (AGENTS.md)

Place router docs under docs/router/ and start framework docs under docs/start/

Files:

  • docs/router/framework/react/guide/document-head-management.md
🪛 LanguageTool
docs/router/framework/react/guide/document-head-management.md

[grammar] ~67-~67: There might be a mistake here.
Context: ... title or meta tags based on route data. You can find the full list of available ...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.18.1)
docs/router/framework/react/guide/document-head-management.md

68-68: Link text should be descriptive

(MD059, descriptive-link-text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Everything documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant