背景描述:
vue项目,做登录页,点击登录按钮时,nextwork显示已经登录成功,但是console中报错
vue-router.esm.js?8c4f:2089 Uncaught (in promise) undefined
并且没有跳转到默认页面。
参考别人博客以为是vue-router跳转方法的问题。
*1.router.push(location)=====window.history.pushState*
想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。
*2.router.replace(location)=====window.history.replaceState*
跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录
因此把push改为了replace,然而并没有解决问题。
-----------------------------------------------------分割线------------------------------------------------------------
//导航守卫 router.beforeEach判断用户是否登录
const token = localStorage.getItem(