想实现的效果是,当我删除最后一个标签的时候,展示首页的模板,我用了$router.push,但是没用,直接使用$router.go,可以实现但是会刷新页面,求解?
if(this.mainNav.length == 0){
console.log(this.$router);
this.$router.push('/mean/home');
}else{
this.$router.go(-1);
}
]
closeTab:function(name){
for(var i = 0; i< this.mainNav.length;i++){
if(this.mainNav[i].name == name){
this.mainNav.splice(i,1);
if(this.mainNav.length == 0){
console.log(this.$router);
this.$router.push('/mean/home');
}else{
this.$router.go(-1);
}
}
}
}
路由
import Vue from 'vue';
import VueRouter from 'vue-router';
import login from '@/components/login';
import index from '@/components/module/index';
import list from '@/components/module/list/list';
import listInfo from '@/components/module/list/list-info';
import home from '@/components/module/home';
Vue.use(VueRouter);
export default new VueRouter({
mode:"history",
routes:[
{
path:"/",
component:index,
redirect:"/mean/home"
},
{
path:"/login",
component:login
},
{
path:"/mean",
component:index,
redirect:"/mean/home",
children:[
{
path:"/mean/home",
component:home,
meta: {
requiresAuth: true
}
},
{
path:"/mean/list",
component:list,
meta: {
requiresAuth: true
}
},
{
path:"/mean/list/:info",
component:listInfo,
meta: {
requiresAuth: true
}
}
]
}
]
})
猜测你的路由是这样子:
设置了name的话,可以试试使用
我们是这么用的,关闭其他标签后默认显示首页,首页没刷新。