fix(nuxt): skip router middleware/redirections for islands (#24421)

Co-authored-by: julien huang <julien.huang@outlook.fr>
This commit is contained in:
Harlan Wilton 2023-11-29 21:11:22 +11:00 committed by GitHub
parent 7c6b6771ab
commit ec0addd8c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,6 +135,11 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
await nuxtApp.runWithContext(() => showError(error))
}
if (import.meta.server && nuxtApp.ssrContext?.islandContext) {
// We're in an island context, and don't need to handle middleware or redirections
return { provide: { router } }
}
const initialLayout = nuxtApp.payload.state._layout
router.beforeEach(async (to, from) => {
to.meta = reactive(to.meta)
@ -200,7 +205,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
if (import.meta.server && failure?.type === 4 /* ErrorTypes.NAVIGATION_ABORTED */) {
return
}
if (to.matched.length === 0 && (!import.meta.server || !nuxtApp.ssrContext?.islandContext)) {
if (to.matched.length === 0) {
await nuxtApp.runWithContext(() => showError(createError({
statusCode: 404,
fatal: false,