我的控制台说:
[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),
})
我的route.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),则不会收到此错误; 有什么想法可以帮助我解决这个问题吗?
答案 0 :(得分:1)
next
必须不带参数来确认导航,否则您将继续触发beforeEach
钩子:
router.beforeEach(function(to, from, next) {
console.log(to.path)
if (to.path !== '/timer') {
next("/timer");
} else {
next();
}
});