Hi,
I have an application with an authentication middleware that redirects user to a login page whenever she tries to access a restricted page. When I click on a link for a first time (from the default layout) then I am redirected to login page with a correct layout, but when I click on the link again (from the login layout), then I am redirected to login page with default layout applied, but it should use login layout.
Simplified version of middleware/auth.js:
export default function ({ route, redirect }) {
if (route.name === 'secret') {
redirect('/login');
}
});
layout/default.vue:
<template>
<div>
<p>This is default layout</p>
<router-link to="secret">Secret</router-link>
</div>
</template>
layout/login.vue:
<template>
<div>
<p>This is login layout</p>
<router-link to="secret">Secret</router-link>
</div>
</template>
pages/login.js:
<template>
<div>This is login page</div>
</template>
<script>
export default {
layout: 'login'
};
</script>
pages/secret.vue:
<template>
<div>
<!-- uses default layout -->
<p>Secret</p>
</div>
</template>
pages/index.vue:
<template>
<div>
<p>Index</p>
</div>
</template>
Here is a screencast describing the current behavior: https://www.screencast.com/t/79ZUqxAXc59H
I'm not called middleware when redirect to pages with another layout from error layout
Yes, you are right that seems to be an another bug - middleware is not called when navigating from the error layout to restricted page using nuxt-link
Hi @JiriChara @skilFullGH
The middleware not called when navigating from the error layout will be fixed in the next release.
I could not reproduce your error @JiriChara
Do you mind forking https://gomix.com/#!/project/nuxt-hello-world and trying to reproduce your behavior?
I am not able to make layouts to work here: https://glitch.com/edit/#!/brainy-apparatus
However here is a repo where you can reproduce the bug: https://github.com/JiriChara/nuxt-middleware Just click on the link to the secret page 2 times. Login page will have a wrong layout then
Thank you for the reproduction @JiriChara, indeed, it does not work as expected in the last release.
Good news, I tried your example with the 0.10 and everything works as expected 🎊

I'll keep this issue open until the 0.10 release is out!
Awesome! Can't wait for the next release :tada:
The 0.10 release it out ✋
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.
Most helpful comment
The 0.10 release it out ✋