Skip to content

Commit 1ece81b

Browse files
committed
fix(i18n): v10 route rule incompatibility
1 parent 97cbbdc commit 1ece81b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/runtime/server/composables/getPathRobotConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,22 @@ export function getPathRobotConfig(e: H3Event, options?: { userAgent?: string, s
8888

8989
// 3. nitro route rules
9090
nitroApp._robotsRuleMatcher = nitroApp._robotsRuleMatcher || createNitroRouteRuleMatcher(e)
91+
let robotRouteRules = nitroApp._robotsRuleMatcher(path)
9192
let routeRulesPath = path
9293
// if we're using i18n we need to strip leading prefixes so the rule will match
93-
if (runtimeConfig.public?.i18n?.locales) {
94+
// note this is for < v10 i18n behavior as it now handles route rules itself
95+
// TODO we may consider checking the version explicitly rather than the presence of the rules
96+
if (runtimeConfig.public?.i18n?.locales && typeof robotRouteRules.robots === 'undefined') {
9497
const { locales } = runtimeConfig.public.i18n as {
9598
locales: { code: string }[]
9699
}
97100
const locale = locales.find(l => routeRulesPath.startsWith(`/${l.code}`))
98101
if (locale) {
99102
routeRulesPath = routeRulesPath.replace(`/${locale.code}`, '')
103+
robotRouteRules = nitroApp._robotsRuleMatcher(routeRulesPath)
100104
}
101105
}
102-
const routeRules = normaliseRobotsRouteRule(nitroApp._robotsRuleMatcher(routeRulesPath))
106+
const routeRules = normaliseRobotsRouteRule(robotRouteRules)
103107
if (routeRules && (typeof routeRules.allow !== 'undefined' || typeof routeRules.rule !== 'undefined')) {
104108
return {
105109
indexable: routeRules.allow ?? false,

0 commit comments

Comments
 (0)