VueRouter beforeEach вызывает ошибку: не удалось преобразовать исключение в строку - PullRequest
0 голосов
/ 25 августа 2018

Моя консоль говорит:

[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),
})

Мой файл rout.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); Любые идеи, которые могут помочь мне это исправить?

1 Ответ

0 голосов
/ 25 августа 2018

next должен быть вызван без параметров для подтверждения навигации, в противном случае вы продолжите вызывать хук beforeEach:

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