router-link
vue-router提供了一个全局组件router-link(取代a标签)
- 能跳转,配置to属性指定路径(必须)。本质还是a标签。
- 默认会提供高亮类名,可以直接设置高亮样式

右键检查,发现多了两个类:

可以直接写样式:

点击即可显示高亮。
router-link-active 模糊匹配
to="/my" 可以匹配/my /my/a /my/b .....
router-link-exact-active 精确匹配to="/my" 只能匹配/my
router-link的类名太长了,可以通过配置实现定制:
const router = new VueRouter({
router:[...],
linkActiveClass:"类名1",
linkExactActiveClass:"类名2"
})
在index.js里面进行配置:

跳转传参
查询参数传参
语法格式: to="/path**?参数名=值**"
对应页面组件接收传递过来的值: $route.query.参数名
动态路由传参配置动态路由:
routes: [
{path:'/search/:words', component:search}
]
配置导航连接:
to="/path/参数值"
对应页面组件接收传值
$route.params.参数名
重定向
重定向:匹配path后,强制跳转path路径
语法:
{path:匹配路径 , redirect : 重定向到的路径}
404
当路径找不到匹配时,给个提示页面
位置:配在路由最后
语法:path:"*" -前面不匹配就命中最后一个

模式设置
路由的路径都带有#,可以在配置router时配置:
mode:"history"
