Well, I have the middleware in directory, middleware/test/test.js
In my page, I used it like this
export default {
middleware: 'test/test'
}
I got an error
TypeError
Cannot read property 'length' of undefined
I'd suggest it's probably an issue with your middleware. Look for the length property - the error should include a line number and work back from there.
Please close the issue. Try SO if you need more help.
This is what I have in middleware
export default function ({store, redirect }) {
if (!store.state.test.questions || !store.state.test.user) {
return redirect('/test')
}
}
Where test is my store's module
Could it be that store.state.test is undefined
But
middleware/test.js , it's works fine
middleware/test/test.js , is error
@homerjam I'm sorry but I couldn't find it in the manual. I supposed it means we cannot use sub folder inside middleware folder?
e.g.
/middlewaare/auth.js => GOOD
/middlewaare/myFolder/auth.js => BAD
What about it? It's important to the environment I'm working on.
The trick was gonna be change the require.context useSubdirectories parameter to true on nuxt.js/lib/app/middleware.js. Or anyway, adding a option to set this definition.
Well, to solve my need I have created a new js file in the path '/middleware' that simply exports the js file of path '/middleware/common' as default. Like that:
/middleware/common/testcommon.js => this is the true middleware
/middleware/test.js => export default require('./common/testecommon').default
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.