How to redirect to home page after logout in nuxt?
14,916
Inside your component you have access to this.$router
So you can easily do:
export default {
name: 'HeadeAfterLogin',
methods: {
LogOut() {
localStorage.removeItem('token')
this.$router.push('/')
}
}
}
Author by
Mohandes
Updated on June 04, 2022Comments
-
Mohandes almost 2 years
after login in site i want when i click to specific button , user log out from site to home page.
here is my
template
code:<template> <nav id="header" class="navbar navbar-expand header-setting"> <div class="main-content"> <div class="notification" @click="LogOut()"></div> </div> </div> </nav> </template>
and here is my
script
code:export default { name: 'HeadeAfterLogin', methods: { LogOut() { localStorage.removeItem('token') } } }
any one can help me to complete LogOut function ?
-
PirateApp over 3 yearsmay wanna use this.$router.replace instead of push
-
Čamo over 2 years@PirateApp Why?
-
PirateApp over 2 years@Čamo if the person hits back button on the browser they ll go back to the page where they were logged in, no?