-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra slashes in URLs when using remix-flat-routes #8
Comments
I took a look at The issue is you should be skipping over any route entries where EDIT: also check for index routes (since they also don't have a const manifestEntry = routes[id]
if (!manifestEntry) {
console.warn(`Could not find a manifest entry for ${id}`)
return
}
+ // pathless layouts are not included
+ if (!manifestEntry.path && !manifiestEntry.index) {
+ return
+ }
let parentId = manifestEntry.parentId
let parent = parentId ? routes[parentId] : null while (parent) {
+ // only add the parent path if it has a path
+ if (parent.path) {
// the root path is '/', so it messes things up if we add another '/'
const parentPath = removeTrailingSlash(parent.path)
path = `${parentPath}/${path}`
+ }
parentId = parent.parentId
parent = parentId ? routes[parentId] : null
} if (path.includes(':')) return
if (id === 'root') return
- const entry: SitemapEntry = { route: removeTrailingSlash(path) }
+ const entry: SitemapEntry = { route: `/${removeTrailingSlash(path)}` }
return entry |
Given these routes, here is the sitemap. ❯ tree app/routes
app/routes
├── _auth+
│ ├── _layout.tsx
│ ├── login.tsx
│ └── profile.tsx
├── _blog+
│ └── hello
│ └── route.tsx
├── _index.tsx
├── _marketing+
│ ├── privacy.tsx
│ └── terms.tsx
├── counter.test.tsx
├── counter.tsx
├── resources+
│ └── healthcheck.tsx
└── sitemap[.xml].ts <Routes>
<Route file="root.tsx">
<Route file="routes/_auth+/_layout.tsx">
<Route path="login" file="routes/_auth+/login.tsx" />
<Route path="profile" file="routes/_auth+/profile.tsx" />
</Route>
<Route path="hello" file="routes/_blog+/hello/route.tsx" />
<Route index file="routes/_index.tsx" />
<Route path="privacy" file="routes/_marketing+/privacy.tsx" />
<Route path="terms" file="routes/_marketing+/terms.tsx" />
<Route path="counter" file="routes/counter.tsx" />
<Route path="resources/healthcheck" file="routes/resources+/healthcheck.tsx" />
<Route path="sitemap.xml" file="routes/sitemap[.xml].ts" />
</Route>
</Routes> sitemap <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://remix.run/login</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/profile</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/hello</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/privacy</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/terms</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://remix.run/counter</loc>
<priority>0.7</priority>
</url>
</urlset> |
Any update on this? Temporary fix: export async function loader({ request, context }: LoaderFunctionArgs) {
const sitemapResponse = await generateSitemap(request, routes, {
siteUrl: "https://yoursite.com",
});
// Get the sitemap content as text
const sitemapString = await sitemapResponse.text();
// Use a regular expression to replace double slashes with single slashes
// but not replace the double slash in https://
const fixedSitemap = sitemapString.replace(/([^:])\/\//g, "$1/");
// Return the fixed sitemap with the correct content type
return new Response(fixedSitemap, {
headers: {
"Content-Type": "application/xml",
"xml-version": "1.0",
encoding: "UTF-8",
},
});
} |
No updates. Please open a PR if you have a fix. |
I've made a PR to fix double slash. |
I believe this library is assuming that folders like
_test+
is a path, when it is not.Is there a way to remove these? Maybe use a regex to condense any repeated slashes (/) into a single slash?
Originally posted by @684efs3 in #7 (comment)
The text was updated successfully, but these errors were encountered: