Home > other >  Nuxt2 CompositionAPI - How can I create Layout Middleware that is ASYNC
Nuxt2 CompositionAPI - How can I create Layout Middleware that is ASYNC

Time:12-07

After developing my webapp I found that I needed to move from using global middleware to layout middleware so that it wasn't triggered upon every page request.

After moving it into my layout under the "middleware" property I found that I needed to make it ASYNC (Fig. 1) but there was nothing that I could find on Nuxt Docs nor SO; the best I could find is a comment saying to "just return a promise". What was suggested is correct for global middleware but not layout middleware.

I feel like I'm missing something obvious here but it would be great if it could be pointed out.

Fig. 1 Fig.1

CodePudding user response:

Turns out the simplest solution was to just declare the function property as "async" rather than trying to return anything specific. (Fig. 2)

Fig. 2 Fig. 2

  • Related