Reputation: 398
I use this code for redirect
beforeCreate() {
if (this.$store.state.user.user.id != null) {
this.$router.push('/')
}
}
my this.$store.state.user.user.id valued in middleware with this code.
import {GET_CARD, GET_USER} from "../store/types/action-types";
export default async function ({store}) {
await store.dispatch('cart/' + GET_CARD)
await store.dispatch('user/user/' + GET_USER)
}
if user logged in show page for 0.5 sec and next redirect. i need dont show login page and next redirect. tnx.
Upvotes: 0
Views: 1099
Reputation: 46814
This answer could maybe help you: https://stackoverflow.com/a/68858238/8816585 (posted minutes ago)
This kind of middleware should work
export default ({ store, redirect }) => {
if (store.state.user.user.id) {
redirect({ name: 'index' }) // or redirect('/')
}
}
Upvotes: 1