fix(nuxt): handle external redirects from routeRules (#26120)

This commit is contained in:
Daniel Roe 2024-03-07 01:17:40 +00:00 committed by GitHub
parent 7551e440e0
commit e9082ad28e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
import { hasProtocol } from 'ufo'
import { defineNuxtRouteMiddleware } from '../composables/router' import { defineNuxtRouteMiddleware } from '../composables/router'
import { getRouteRules } from '../composables/manifest' import { getRouteRules } from '../composables/manifest'
@ -5,6 +6,10 @@ export default defineNuxtRouteMiddleware(async (to) => {
if (import.meta.server || import.meta.test) { return } if (import.meta.server || import.meta.test) { return }
const rules = await getRouteRules(to.path) const rules = await getRouteRules(to.path)
if (rules.redirect) { if (rules.redirect) {
if (hasProtocol(rules.redirect, { acceptRelative: true })) {
window.location.href = rules.redirect
return false
}
return rules.redirect return rules.redirect
} }
}) })