📝 更新(category.scss):优化链接样式,添加活动状态样式

 功能(index.tsx):替换Link为NavLink组件,支持活动状态样式
This commit is contained in:
ruotongyu
2024-06-16 12:29:34 +08:00
parent 90bec306d8
commit 543cf8e9b6
2 changed files with 13 additions and 3 deletions

View File

@@ -9,9 +9,15 @@
.categories{
@apply border-r bg-slate-100 text-xs text-slate-700 overflow-y-auto;
grid-area: categories;
.item{
// link 编译完是 a 标题
a{
@apply p-1 py-1 truncate cursor-pointer block;
&.active{
// mx-1 外边距
@apply bg-blue-700 text-white mx-1 rounded-md;
}
}
}
.nav {

View File

@@ -1,4 +1,4 @@
import { Link, Outlet, useLoaderData } from "react-router-dom"
import { Link, NavLink, Outlet, useLoaderData } from "react-router-dom"
import "./category.scss"
import { Add, DatabaseConfig } from "@icon-park/react"
@@ -8,7 +8,11 @@ export const Category = () => {
<main className="category-page">
<div className="categories">
{categories.map((category) => (
<Link to={`/config/category/contentList/${category.id}`} key={category.id} className="item" >{category.name}</Link>
<NavLink
to={`/config/category/contentList/${category.id}`}
key={category.id}
className={({isActive}) => (isActive ? 'active' : '')}
>{category.name}</NavLink>
))}
</div>