fix(layout-middleware): Fix issue #4724

This commit is contained in:
Sébastien Chopin 2019-01-10 18:59:56 +01:00
parent 2bde11f77d
commit 521ac20e29
2 changed files with 5 additions and 3 deletions

View File

@ -196,8 +196,9 @@ function callMiddleware(Components, context, layout) {
// If layout is undefined, only call global middleware // If layout is undefined, only call global middleware
if (typeof layout !== 'undefined') { if (typeof layout !== 'undefined') {
midd = [] // Exclude global middleware if layout defined (already called before) midd = [] // Exclude global middleware if layout defined (already called before)
if (layout.middleware) { const layoutMiddleware = layout.middleware || layout.options.middleware
midd = midd.concat(layout.middleware) if (layoutMiddleware) {
midd = midd.concat(layoutMiddleware)
} }
Components.forEach((Component) => { Components.forEach((Component) => {
if (Component.options.middleware) { if (Component.options.middleware) {

View File

@ -136,7 +136,8 @@ export default async (ssrContext) => {
** Call middleware (layout + pages) ** Call middleware (layout + pages)
*/ */
midd = [] midd = []
if (layout.middleware) midd = midd.concat(layout.middleware) const layoutMiddleware = layout.middleware || layout.options.middleware
if (layoutMiddleware) midd = midd.concat(layoutMiddleware)
Components.forEach((Component) => { Components.forEach((Component) => {
if (Component.options.middleware) { if (Component.options.middleware) {
midd = midd.concat(Component.options.middleware) midd = midd.concat(Component.options.middleware)