【问题标题】:Router.push reloads page with '?#' added to the URLRouter.push 重新加载页面,并在 URL 中添加了 '?#'
【发布时间】:2020-08-23 13:14:42
【问题描述】:

当用户单击登录按钮时,它会触发此功能以使用 AWS Cognito:

signIn() {
  let username = this.emailIn;
  let password = this.passwordIn;
  Auth.signIn(username, password)
    .then(user => {
      this.$router.push({ path: "dashboard" });
      this.$store.commit("SETUSER", user);
      this.$store.commit("CHANGESIGNEDIN", true);
    })
    .catch(err => console.log(err));
}

函数触发后,页面重新加载并在 url 中添加一个 '?#'。如果我再次尝试登录,则它可以正常工作...

我在我的 index.js 中为 Vue 路由器设置了一个非常简单的设置:

import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Dashboard from "../views/Dashboard.vue";
import Leads from "../views/Leads.vue";
import SignUp from "../views/SignUp.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/dashboard",
    name: "Dashboard",
    component: Dashboard,
  },
  {
    path: "/leads",
    name: "Leads",
    component: Leads,
  },
  {
    path: "/signup",
    name: "SignUp",
    component: SignUp,
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    你少了一个斜线。你的行应该是:

    this.$router.push({ path: "/dashboard" });
    

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 1970-01-01
      • 2020-03-19
      • 2014-04-14
      • 1970-01-01
      • 2020-08-25
      • 2015-03-08
      • 2012-07-28
      • 1970-01-01
      相关资源
      最近更新 更多