Skip to content

Commit

Permalink
fix(nuxt): skip router middleware/redirections for islands (#24421)
Browse files Browse the repository at this point in the history
Co-authored-by: julien huang <julien.huang@outlook.fr>
  • Loading branch information
harlan-zw and huang-julien committed Nov 29, 2023
1 parent 7c6b677 commit ec0addd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/nuxt/src/pages/runtime/plugins/router.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ec0addd

Please sign in to comment.