i have declare a middleware that check role of every routes in nuxt.config.js. but want to disable in some pages.
// in nuxt.config.js =>
router: {
middleware: ['role']
},
// in middleware/role.js =>
export default function ({app}) {
if (!window.localStorage.getItem('auth.token')) {
//app.router.push('/auth/login');
console.log('middleware');
}
}
// in login.vue =>
export default {
role: false,
}
// in root page =>
export default {
role: false,
middleware({app}){
if (!window.localStorage.getItem('auth.token')) {
app.router.push('/auth/login');
}
},
}
when token is empty and redirect user, the page is loading again and again so i comment this redirect and console log a message, to check what happen. this role middleware is loading on that page where the role middleware is set to false. check the image below.
here you can see middleware printed twice, one for root('/') and another one for login page (here i disabled role middleware). how to disable this middleware to this login page.