mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
fix(nuxt): provide fallback route (#22580)
This commit is contained in:
parent
758ae76709
commit
99375d688c
@ -14,13 +14,13 @@ export const RouteInjectionPlugin = (nuxt: Nuxt) => createUnplugin(() => {
|
|||||||
return isVue(id, { type: ['template', 'script'] })
|
return isVue(id, { type: ['template', 'script'] })
|
||||||
},
|
},
|
||||||
transform (code) {
|
transform (code) {
|
||||||
if (!INJECTION_SINGLE_RE.test(code)) { return }
|
if (!INJECTION_SINGLE_RE.test(code) || code.includes('_ctx._.provides[__nuxt_route_symbol')) { return }
|
||||||
|
|
||||||
let replaced = false
|
let replaced = false
|
||||||
const s = new MagicString(code)
|
const s = new MagicString(code)
|
||||||
s.replace(INJECTION_RE, () => {
|
s.replace(INJECTION_RE, () => {
|
||||||
replaced = true
|
replaced = true
|
||||||
return '_ctx._.provides[__nuxt_route_symbol]'
|
return '(_ctx._.provides[__nuxt_route_symbol] || _ctx.$route)'
|
||||||
})
|
})
|
||||||
if (replaced) {
|
if (replaced) {
|
||||||
s.prepend('import { PageRouteSymbol as __nuxt_route_symbol } from \'#app/components/injections\';\n')
|
s.prepend('import { PageRouteSymbol as __nuxt_route_symbol } from \'#app/components/injections\';\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user