mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
fix(nuxt3): update legacy plugin (closes #1200)
This commit is contained in:
parent
d8d10febd5
commit
5e903ae176
@ -123,8 +123,8 @@ const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
|
||||
|
||||
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
|
||||
|
||||
export const legacyPlugin = (nuxt: NuxtApp) => {
|
||||
nuxt._legacyContext = new Proxy(nuxt, {
|
||||
export const legacyPlugin = (nuxtApp: NuxtApp) => {
|
||||
nuxtApp._legacyContext = new Proxy(nuxtApp, {
|
||||
get (nuxt, p: keyof LegacyContext | keyof LegacyContext['ssrContext']) {
|
||||
// Unsupported keys
|
||||
if (unsupported.has(p)) {
|
||||
@ -137,7 +137,7 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
||||
|
||||
// vue-router implementation
|
||||
if (routerKeys.includes(p)) {
|
||||
if (!('$router' in nuxt)) {
|
||||
if (!('$router' in nuxtApp)) {
|
||||
return mock('vue-router is not being used in this project.')
|
||||
}
|
||||
switch (p) {
|
||||
@ -170,12 +170,12 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
||||
return nuxt.payload.data
|
||||
}
|
||||
|
||||
if (p in nuxt.app) {
|
||||
return nuxt.app[p]
|
||||
if (p in nuxtApp.vueApp) {
|
||||
return nuxtApp.vueApp[p]
|
||||
}
|
||||
|
||||
if (p in nuxt) {
|
||||
return nuxt[p]
|
||||
if (p in nuxtApp) {
|
||||
return nuxtApp[p]
|
||||
}
|
||||
|
||||
return mock(`Accessing ${p} is not supported in Nuxt3.`)
|
||||
@ -183,15 +183,15 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
||||
}) as unknown as LegacyContext
|
||||
|
||||
if (process.client) {
|
||||
nuxt.hook('app:created', () => {
|
||||
const legacyApp = { ...nuxt.app } as LegacyApp
|
||||
nuxtApp.hook('app:created', () => {
|
||||
const legacyApp = { ...nuxtApp.vueApp } as LegacyApp
|
||||
legacyApp.$root = legacyApp
|
||||
|
||||
// @ts-ignore
|
||||
// TODO: https://github.com/nuxt/framework/issues/244
|
||||
legacyApp.constructor = legacyApp
|
||||
|
||||
window[`$${nuxt.globalName}`] = legacyApp
|
||||
window[`$${nuxtApp.globalName}`] = legacyApp
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user