VueRouter's beforeEach causes error: failed to convert exception to string

VueRouter's beforeEach causes error: failed to convert exception to string

我的控制台显示:

[vue-router] uncaught error during route navigation:
<failed to convert exception to string>

导致该错误的行是 main.js 中的行:

next('/login')

我的 main.js 文件:

import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import App from './App.vue'
import Routes from './routes'

import { store } from './store/store';


Vue.use(VueRouter);

const router = new VueRouter({
    routes: Routes
})

router.beforeEach((to, from, next) => {
    next('/login');
})

var vm = new Vue({
  el: '#app',
  store: store,
  router: router,
  render: h => h(App),
})

我的 routes.js 文件:

export default [
    { path: '/', component: Game, cors: true },
    { path: '/login', component: Login },
    { path: '/signin', component: SignIn },
    { path: '/gamerouter', component: GameRouter },
    { path: '/waitingforplayers', component: WaitingForPlayers, name: "buba" },
    { path: '/selectPlayersForTeams', component: SelectPlayersForTeams },
    { path: '/startStatistics', component: StartStatistics },
    { path: '/gamelocked', component: GameLocked },
    { path: '/answering', component: Answering },

]

如果我输入 next('/'),​​我也会得到这个错误,但是如果我写 next() 或 next(false),我不会得到这个错误; 有什么想法可以帮助我解决这个问题吗?

next 必须在不带参数的情况下调用以确认导航,否则您将继续触发 beforeEach 挂钩:

router.beforeEach(function(to, from, next) {
  console.log(to.path)
  if (to.path !== '/timer') {
    next("/timer");
  } else {
    next();
  }
});