vuerouter-7._路由高亮

Posted xiao-peng-ji

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vuerouter-7._路由高亮相关的知识,希望对你有一定的参考价值。

1.router-link-exact-active 精准匹配

2.router-link-active 匹配

配置:------------------------------------------------------------------------------------------------------

import Vue from ‘vue‘
import VueRouter from ‘vue-router‘
//@表示寻找根目录
import HelloWorld from ‘@/components/HelloWorld‘
import learn from ‘@/components/learn‘
import Basee from ‘@/components/basee‘
import Http from ‘@/components/http‘
import NotFound from ‘@/components/404‘
Vue.use(VueRouter)
//创建路由
export default new VueRouter(
//mode:‘history‘,
linkActiveClass:"active",
linkExactActiveClass:"currentactive",
routes: [
path: "/h/:id",
name: "HelloWorld", //可以作为跳转使用
component: HelloWorld
,

path: "/learn/:id",
name: "learn",
component: learn,
children: [
path: "basee",
component: Basee
,

path: "http",
component: Http

]
,

path:"/",
//重定向
redirect:"/learn"
,

path:"*",
//404
component:NotFound

]
)

2.样式-----------------------------------

<template>
<div id="app">
<img src="./assets/logo.png">
<ul>
<!-- <router-link to="/h" tag="li">HelloWorld</router-link>
<router-link to="/learn" tag="li">learn</router-link> -->
<router-link :to="name:‘HelloWorld‘,params:id:helloparams" tag="li">HelloWorld</router-link>
<router-link :to="name:‘learn‘" tag="li">learn</router-link>
</ul>
<button class="btn" @click="gotoHello">去learns</button>
<router-view />
</div>
</template>

<script>
export default
name: ‘App‘,
components:

,
data()
return
helloparams:"hellodemo",
clickParams:"hahaha"

,
methods:
gotoHello()
//this.$router.push("/h")
//this.$router.replace("/h")
//this.$router.go(-1)
this.$router.push(name:"learn",params:id:this.clickParams)



</script>

<style>
#app
font-family: ‘Avenir‘, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;

ul li
text-align: center;
display: inline-block;
text-decoration: underline;
cursor: pointer;
color: blue;

ul li+li
margin-left: 20px;

.btn
border: 1px solid #fff;
padding: 5px;
color: #fff;
background-color: #0000FF;
cursor: pointer;

/* router-link-exact-active 精准匹配
*/
/* .router-link-activecolor:red; */
.activecolor:red;
.currentactiveborder:1px solid blue;
</style>

 

以上是关于vuerouter-7._路由高亮的主要内容,如果未能解决你的问题,请参考以下文章

Vue 路由:未捕获类型错误:window.Vue.use 不是函数

VUE路由高亮或导航高亮(有图有真相,学无止境,欢迎交流)

element-ui,router.push到其他路由,菜单栏不会高亮对应的路由

Vue-router结合transition实现app前进后退动画切换效果

react路由---navlink解决首页路由高亮重复匹配问题

vue父路由默认选中第一个子路由,切换子路由让父路由高亮不会消失