Skip to content

Commit

Permalink
fix: trailing slash urls can discover route rules
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jan 5, 2023
1 parent 904b1d8 commit 55b440a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export default defineNuxtConfig({
},
routeRules: {
'/secret': { index: false },
'/about': { sitemap: { changefreq: 'daily', priority: 0.3 } }
'/about': { sitemap: { changefreq: 'daily', priority: 0.3 } },
}
})
7 changes: 4 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ declare module 'nitropack' {
// fix order
.sort()
// check route rules
.map((path) => {
const routeRules = defu({}, ..._routeRulesMatcher.matchAll(path).reverse())
.map((route) => {
// route matcher assumes all routes have no trailing slash
const routeRules = defu({}, ..._routeRulesMatcher.matchAll(withoutTrailingSlash(route)).reverse())
// @ts-expect-error untyped
if (routeRules.index === false)
return false

// @ts-expect-error untyped
return { url: fixSlashes(path), ...(routeRules.sitemap || {}) }
return { url: route, ...(routeRules.sitemap || {}) }
})
.filter(Boolean)

Expand Down

0 comments on commit 55b440a

Please sign in to comment.