kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
640 stars 22 forks source link

Generated sitemap results in extra slashes #105

Closed 684efs3 closed 4 months ago

684efs3 commented 5 months ago

I am using remix-flat-routes with Remix+Vite as well as nasa-gcn/remix-seo.

The generated sitemap has extra slashes after the domain name, e.g. https://abc.com//xyz.

My routes folder looks something like this:

routes
   _auth+
     login.jsx
     profile.jsx
   _marketing+
     privacy.mdx
     terms.mdx
   _blog+
     hello
       route.jsx
     test.mdx

Only /login and /profile are correctly generated in the sitemap. The other ones will have an extra slash.

My vite.config.ts looks like this:

remix({
      ignoredRouteFiles: ['**/*'],
      routes: async defineRoutes => {
        return flatRoutes('routes', defineRoutes)
      }
    }),

My sitemap[.]xml.js looks like this:

import { generateSitemap } from '@nasa-gcn/remix-seo'
import { siteConfig } from '../../utils/site-config'

export async function loader ({ request }) {
  //@ts-ignore - This may fail during docker build typecheck if the app isn't build yet
  let build = await (import.meta.env.DEV
    ? import('../../build/server/index.js')
    : import(
        /* @vite-ignore */
        import.meta.resolve('../../build/server/index.js')
      ))

  return generateSitemap(request, build.routes, {
    siteUrl: siteConfig.url,
    headers: {
      'Cache-Control': `public, max-age=${60 * 5}`
    }
  })
}

@github.com/nasa-gcn/remix-seo/issues/7

lpsinger commented 4 months ago

See https://github.com/nasa-gcn/remix-seo/issues/8.

kiliman commented 4 months ago

Sorry for not seeing this sooner. I'll take a look.

kiliman commented 4 months ago

I believe this is an issue with remix-seo.

https://github.com/nasa-gcn/remix-seo/issues/7#issuecomment-1954329696