Vue.js 使用router.beforeach时,Vue路由器视图未呈现
我正在使用Vue路由器,我需要使用Vue.js 使用router.beforeach时,Vue路由器视图未呈现,vue.js,vue-component,vue-router,Vue.js,Vue Component,Vue Router,我正在使用Vue路由器,我需要使用路由器。在每次回调之前,确定某条路由是否被击中。唯一的问题是使用回调时,不会呈现任何内容 app.vue <template> <div id="app"> <navComponent></navComponent> <router-view></router-view> </div> </template> <
路由器。在每次
回调之前,确定某条路由是否被击中。唯一的问题是使用回调时,
不会呈现任何内容
app.vue
<template>
<div id="app">
<navComponent></navComponent>
<router-view></router-view>
</div>
</template>
<script>
import navComponent from './nav'
export default {
components: {
navComponent
}
}
</script>
app.js
import VueRouter from 'vue-router';
export default new VueRouter({
routes: [
{
path: '/',
component: require('./views/home')
},
{
path: '/logout'
}
],
linkActiveClass: 'is-active'
});
import './bootstrap';
import router from './routes';
import app from './views/app';
router.beforeEach((to, from, next) => { //if this callback was commented out the <router-view></router-view> would render what i want it to render
if(to.fullPath === '/logout') {
axios.get('/logout');
router.push('/');
}
});
new Vue({
el: "#app",
router,
render: h => h(app)
});
import./bootstrap';
从“./routes”导入路由器;
从“./views/app”导入应用程序;
beforeach((to,from,next)=>{//如果此回调被注释掉,则将呈现我希望它呈现的内容
如果(to.fullPath=='/logout'){
get('/logout');
路由器推送('/');
}
});
新Vue({
el:“应用程序”,
路由器,
渲染:h=>h(应用程序)
});
如果修复非常简单,请提前道歉,我似乎找不到解决方案
谢谢。所以我错过了
next()代码>在每次
回调之前的内调用
import './bootstrap';
import router from './routes';
import app from './views/app';
router.beforeEach((to, from, next) => {
if(to.fullPath === '/logout') {
axios.get('/logout');
router.push('/');
}
next(); //this is needed
});
结果我错过了next()代码>在每次
回调之前的内调用
import './bootstrap';
import router from './routes';
import app from './views/app';
router.beforeEach((to, from, next) => {
if(to.fullPath === '/logout') {
axios.get('/logout');
router.push('/');
}
next(); //this is needed
});