我为我的自托管应用提供了简单的身份验证系统。通过有效的用户名和密码后,我需要重定向路由器视图。
[不幸的是,当我打电话给router.push("/")
时,什么都没有发生。然后,我必须再次单击“登录”或手动重新加载页面或使用router.go()
。
登录后我无法重新加载所有页面,我只需要更新router-view
。
我搜索了很多问题,但没有答案。
export const authentication = {
namespaced: true,
state: initialState,
actions: {
login({
dispatch,
commit
}, {
username,
password
}) {
commit("loginRequest", {
username
});
userService.login(username, password).then(
user => {
commit("loginSuccess", user);
// FIXME
// when it is called it always generate error `undefinded`...
router.push({
url: "/"
}).catch(err => {
console.log(err);
});
// router.go(); // I can not do this!
},
error => {
commit("loginFailure", error);
dispatch("alert/error", error, {
root: true
});
}
);
},
logout({
commit
}) {
userService.logout();
commit("logout");
}
};
你有什么想法,怎么了?
您是否尝试过这个:this.$router.push({ path: '/' });
?