Skip to content

fix(sitemap): remove layout routes from the sitemap list#20

Open
mateussilva92 wants to merge 1 commit intocode-forge-io:mainfrom
mateussilva92:bugfix/duplicated-routes
Open

fix(sitemap): remove layout routes from the sitemap list#20
mateussilva92 wants to merge 1 commit intocode-forge-io:mainfrom
mateussilva92:bugfix/duplicated-routes

Conversation

@mateussilva92
Copy link

Fixes #12

Description

This PR fixes an issue where some routes were being duplicated in the sitemap for Remix/React Router v7.
This was being cause by layout routes were being treated as normal routes which they shouldn't be since they don't have any path associated to them that the user can navigate to.

The changes include:

  • Filtering layout routes by checking if they the path is not undefined or if the index is set to true.

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

This was tested locally directly on a React Router v7 project that I'm currently working on. I defined layout for the home route which cased the home route to appear twice on the sitemap. After the changes it only appear once.

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the UI is working as expected and is satisfactory
  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)

Screenshots (if appropriate):

Questions (if appropriate):

Comment on lines +38 to +42
return Object.values(routes)
.filter((route) => {
// Filter out layouts from the routes
return route?.path !== undefined || route?.index
})

Choose a reason for hiding this comment

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

Wouldn't that ignore all child routes here? I think in the case of a layout route, all children should be spread into the parent for processing.

Copy link
Author

@mateussilva92 mateussilva92 Feb 26, 2026

Choose a reason for hiding this comment

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

Not really. If that was the case the old code would have ignore them already since it only goes one level deep. The routes used here should come from virtual:react-router/server-build which already has all the routes flattened so none of the routes have any children, this can even be checked on the type of InternalServerRoute which even omits the children.

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.

Duplicate urls returned by generateRemixSitemap using React Router 7

2 participants