8000 fix(nuxt): provide fallback route (#22580) · nuxt/nuxt@99375d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99375d6

Browse files
authored
fix(nuxt): provide fallback route (#22580)
1 parent 758ae76 commit 99375d6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/nuxt/src/pages/route-injection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const RouteInjectionPlugin = (nuxt: Nuxt) =& 8F1F gt; createUnplugin(() => {
1414
return isVue(id, { type: ['template', 'script'] })
1515
},
1616
transform (code) {
17-
if (!INJECTION_SINGLE_RE.test(code)) { return }
17+
if (!INJECTION_SINGLE_RE.test(code) || code.includes('_ctx._.provides[__nuxt_route_symbol')) { return }
1818

1919
let replaced = false
2020
const s = new MagicString(code)
2121
s.replace(INJECTION_RE, () => {
2222
replaced = true
23-
return '_ctx._.provides[__nuxt_route_symbol]'
23+
return '(_ctx._.provides[__nuxt_route_symbol] || _ctx.$route)'
2424
})
2525
if (replaced) {
2626
s.prepend('import { PageRouteSymbol as __nuxt_route_symbol } from \'#app/components/injections\';\n')

0 commit comments

Comments
 (0)
0