From 158c3907fec6ffe8d96a57f8264cf431db2ee3e8 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Mon, 30 Aug 2021 21:34:31 +0200 Subject: [PATCH] fix: crash on using $nuxtI18nHead from nuxt.config's head Fixes #1266 --- src/templates/plugin.routing.js | 3 ++- test/fixture/basic/nuxt.config.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/templates/plugin.routing.js b/src/templates/plugin.routing.js index 74691e159..feaadfb34 100644 --- a/src/templates/plugin.routing.js +++ b/src/templates/plugin.routing.js @@ -191,7 +191,8 @@ const VueInstanceProxy = function (targetFunction) { localePath: this.localePath, localeRoute: this.localeRoute, localeLocation: this.localeLocation, - req: process.server ? this.$ssrContext.req : null, + // @ts-ignore + req: process.server ? this.$root.context?.req || this.$ssrContext?.req : null, route: this.$route, router: this.$router, store: this.$store diff --git a/test/fixture/basic/nuxt.config.js b/test/fixture/basic/nuxt.config.js index c6b2135d6..f704fb007 100644 --- a/test/fixture/basic/nuxt.config.js +++ b/test/fixture/basic/nuxt.config.js @@ -5,7 +5,11 @@ import BaseConfig from '../base.config' const config = { ...BaseConfig, buildDir: resolve(__dirname, '.nuxt'), - srcDir: __dirname + srcDir: __dirname, + // Verifies that there is no SSR crash when used that way. + head () { + return this.$nuxtI18nHead({ addSeoAttributes: true }) + } } module.exports = config