Middleware frequently need to check state such as whether a user is logged in.
If you want to redirect users to a login page based on their logged in status on every page, you cannot do this via a middleware in SSR mode.
Changing the whole app to SPA mode for this one feature will slow the entire app down.
A flag in nuxt.config.json to run middlewares in client side only.
I would suggest the feature of using middleware.client.js and middleware.server.js vs this flag so it matches the same feature of plugins. This would also eliminate a bunch of if(process.client) stuff as well. I may be working on a pull on this at some point but currently don't have time.
We are using nuxt in full static with mode 'universal' to have fully pre-rendered pages and we assumed the middleware will only be executed client-side, well, because it is static. But apparently this is not the case. I do not understand why we cannot have client-side only middleware (with full static). In Static mode server-side rendering should mean _rendering_ not execution of middleware -- this is highly confusing.
The weirdest was that some middleware are executed on client-side on the first page load and others are not. Switching to SPA mode fixes it, but this slows down a static page unnecessarily -- and defeats the purpose of a static build.
@theDevelopper what makes you think middleware is being ran server side with full static?
when building the static pages I see the output from the middlewares during the build process in the terminal. The middleware is clearly being executed during build.
Most helpful comment
I would suggest the feature of using middleware.client.js and middleware.server.js vs this flag so it matches the same feature of plugins. This would also eliminate a bunch of if(process.client) stuff as well. I may be working on a pull on this at some point but currently don't have time.