Skip to content

Commit

Permalink
fix(nuxt): handle external redirects from routeRules (#26120)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 7, 2024
1 parent 7551e44 commit e9082ad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/nuxt/src/app/middleware/manifest-route-rule.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { hasProtocol } from 'ufo'
import { defineNuxtRouteMiddleware } from '../composables/router'
import { getRouteRules } from '../composables/manifest'

export default defineNuxtRouteMiddleware(async (to) => {
if (import.meta.server || import.meta.test) { return }
const rules = await getRouteRules(to.path)
if (rules.redirect) {
if (hasProtocol(rules.redirect, { acceptRelative: true })) {
window.location.href = rules.redirect
return false
}
return rules.redirect
}
})

0 comments on commit e9082ad

Please sign in to comment.