1、默认路径可以通过redirect来重定向
const routes = [ { path: ‘/‘ , redirect: ‘/home‘}, { path: ‘/home‘, name: ‘home‘ ,component: HomePage}, { path: ‘/list‘, name: ‘list‘, component: ListPage}, { path: ‘/cart‘, name: ‘cart‘ , component: CartPage}, { path: ‘/mine‘, name: ‘mine‘ , component: MinePage}, { path: ‘/detail/:id/:name?‘, name: ‘detail‘, component: DetailPage}, // { path: ‘*‘, component: NotFoundPage} ];
2、可以通过*来处理404组件
3、组件切换,通过静态方式和动态方法
1、静态方式 :<router-link>
<router-link to="/home">首页</router-link> | <router-link :to="‘/list‘">列表</router-link> | <router-link :to="{path: ‘/cart‘}">购物车</router-link> | <router-link :to="{name: ‘mine‘}">我的</router-link> 通过acitve-class来指定激活样式或使用默认的样式,默认类名为 .router-link-active 通过tag属性可以修改生成标签,默认生成标签为a
· 2、动态方式: $router对象
原文:https://www.cnblogs.com/dfx9527/p/14456405.html