10.Vue 路由重定向

在Vue中可以设置路由的重定向,用法如下:

1.redirect: '/path'、redirect:{}:

this.$routes 和 this.$route区别:8.Vue路由(路由配置、传参、获取参数)

案例:

exprot default new Router({
  routes: [
    {
      path: '/',
      //redirect: '/RouterB',
      redirect: {name: 'RouterB', params: {id:'0001', title:'0002'}}
    }
  ]
});

2.使用 *通配符,表示没有匹配使用该路由规则匹配,这个建议写在路由规则最下面:

案例

import notFound from '../page/notFound/notFound'

exprot default new Router({
  routes:[
    {
      .....
    },
    //最后使用*通配符,表示以上规则不满足则进行该规则(比如未发现等)
    {
      path: '*',
      component: notFound
    }
  ]
});

3. notFound.vue

<template>
  <div>
      页面飞到外太空去了....
  </div>
</template>
<script>
export default {
  
}
</script>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。