Skip to content

Duplicate urls returned by generateRemixSitemap using React Router 7 #12

@nikolailehbrink

Description

@nikolailehbrink

Hi @AlemTuzlak, first of thanks for the package!

I do not know if its only related to RR7 or Remix v2 aswell, but when I use the following code to generate the sitemap, the generateRemixSitemap helper function returns duplicate links. Any chance to fix this or do you know why that is happening?

import { generateRemixSitemap } from "@forge42/seo-tools/remix/sitemap";
import type { Route } from "./+types/sitemap.xml";
import { href } from "react-router";

export const loader = async ({ request }: Route.LoaderArgs) => {
  const { routes } = await import("virtual:react-router/server-build");
  const sitemap = await generateRemixSitemap({
    domain: new URL(request.url).origin,
    ignore: [href("/api/chat"), href("/legal-notice"), href("/privacy-policy")],
    // @ts-expect-error Type mismatch, maybe related to a stricter type mentioned in release notes for v.7.0.0
    // https://github.com/forge-42/seo-tools/issues/8
    routes,
  });

  return new Response(sitemap, {
    headers: {
      "Content-Type": "application/xml",
    },
  });
};
// routes.ts
import {
  type RouteConfig,
  index,
  layout,
  prefix,
  route,
} from "@react-router/dev/routes";

export default [
  layout("routes/layout.tsx", [
    index("routes/index.tsx"),
    ...
    route("sitemap.xml", "routes/sitemap.xml.ts"),
    route("robots.txt", "routes/robots.txt.ts"),
  ]),
] satisfies RouteConfig;

The generated sitemap:

<url>
  <loc>http://localhost:5173/</loc>
</url>
<url>
  <loc>http://localhost:5173/</loc>
</url>
<url>
  <loc>http://localhost:5173/chat</loc>
</url>
<url>
  <loc>http://localhost:5173/blog</loc>
</url>
<url>
  <loc>http://localhost:5173/</loc>
</url>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions