Vue Router首次登录路径异常:路径自动添加?号问题求助
Vue Router首次登录页面重载异常问题
我在Web应用的登录页面使用Vue Router时遇到以下问题:首次输入账号密码提交后,页面会发生重载,路径从http://localhost:8080/#/login变为http://localhost:8080/?#/login;但再次尝试登录时,Router就能正常工作,可成功进入系统。
Vue Router配置
import Vue from 'vue'; import VueRouter from 'vue-router'; import routes from './routes'; Vue.use(VueRouter); // configure router const router = new VueRouter({ routes, // short for routes: routes linkActiveClass: 'active', scrollBehavior: (to, from ,savedPosition) => { if (savedPosition) { return savedPosition; } if (to.hash) { return { selector: to.hash }; } return { x: 0, y: 0 }; } }); export default router;
导航守卫代码(运行正常)
async function guardMyroute(to, from, next) { if(store.state.token) { const payload = { access_token: store.state.token, Nom: store.state.Nom } let Data = await axios.post('/token', payload).then((res => res.data)) if (Data === true) { next(); // allow to enter route } if (Data === false) { next({path: '/Home'}); } } else{next({path:'/Home'});} }
内容的提问来源于stack exchange,提问作者Sebastien Christophe
相关产品推荐
相关产品推荐

