美文网首页
Vue router中alias和redirect的区别

Vue router中alias和redirect的区别

作者: Gino_Li | 来源:发表于2019-04-29 14:05 被阅读0次

redirect

<router-link to="/home"></router-link>
                {
                    path:'/home',
                    name:'home',
                    component:()=>import('@/components/a.vue'),
                    redirect:'/index' //重定向
                }

点击进入后显示的url

localhost:8080/#/index

显示的是重定向后的地址即index

alias

        {
            path:'/home',
            component:Home,
            name:'home',
            alias:"/h",   //别名
        }

点击进入后显示的url

localhost:8080/#/h

显示的是别名h

总结

  • redirect:用户访问/home页面时,会跳转到/index页面,url会显示/index

  • alias:当用户需要访问/home页面时,可以使用它的别名/h,url会显示/h

相关文章

网友评论

      本文标题:Vue router中alias和redirect的区别

      本文链接:https://www.haomeiwen.com/subject/qqjynqtx.html