You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 22:11:06