vue tab关闭标签后默认展示首页

想实现的效果是,当我删除最后一个标签的时候,展示首页的模板,我用了$router.push,但是没用,直接使用$router.go,可以实现但是会刷新页面,求解?

if(this.mainNav.length == 0){
                        console.log(this.$router);
                        this.$router.push('/mean/home');
                    }else{
                        this.$router.go(-1);
                    }

clipboard.png
]

clipboard.png

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 
                    }
                }
            ]
        }
    ]
})
阅读 3.3k
1 个回答

猜测你的路由是这样子:

{
        path: '/mean/home',
        name: 'home',
        component: .......,
        //.....
   }

设置了name的话,可以试试使用

this.$router.push({
   name: 'home'
});

我们是这么用的,关闭其他标签后默认显示首页,首页没刷新。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题