Skip to content

Commit b519903

Browse files
committed
Fix active link issue in navbar
Signed-off-by: nurRiyad <asadnurriyad@gmail.com>
1 parent 0b82562 commit b519903

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

components/main/header.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,36 @@ const colorMode = useColorMode()
55
function onClick(val: string) {
66
colorMode.preference = val
77
}
8+
9+
const route = useRoute()
10+
function isActive(path: string) {
11+
return route.path.startsWith(path)
12+
}
813
</script>
914

1015
<template>
1116
<div class="py-5 border-b dark:border-gray-800 font-semibold">
1217
<div class="flex px-6 container max-w-5xl justify-between mx-auto items-baseline ">
1318
<ul class="flex items-baseline space-x-5">
1419
<li class="text-base sm:text-2xl font-bold">
15-
<NuxtLink to="/">
20+
<NuxtLink to="/" :class="{ underline: $route.path === '/' }">
1621
{{ navbarData.homeTitle }}
1722
</NuxtLink>
1823
</li>
1924
</ul>
2025
<ul class="flex items-center space-x-3 sm:space-x-6 text-sm sm:text-lg">
2126
<li>
22-
<NuxtLink to="/blogs">
27+
<NuxtLink to="/blogs" :class="{ underline: isActive('/blogs') }">
2328
Blogs
2429
</NuxtLink>
2530
</li>
2631
<li>
27-
<NuxtLink to="/categories">
32+
<NuxtLink to="/categories" :class="{ underline: isActive('/categories') }">
2833
Categories
2934
</NuxtLink>
3035
</li>
3136
<li title="About Me">
32-
<NuxtLink to="/about" aria-label="About me">
37+
<NuxtLink to="/about" aria-label="About me" :class="{ underline: $route.path === '/about' }">
3338
About
3439
</NuxtLink>
3540
</li>
@@ -63,9 +68,3 @@ function onClick(val: string) {
6368
</div>
6469
</div>
6570
</template>
66-
67-
<style>
68-
.router-link-active .router-link-exact-active {
69-
@apply underline
70-
}
71-
</style>

0 commit comments

Comments
 (0)