ui(autoMate): 添加选中样式以及自动跳转至第一个内容页

📝 ui(autoMate): 引入react的useEffect和useNavigate功能
This commit is contained in:
ruotongyu
2024-06-17 22:44:45 +08:00
parent d120fbe751
commit a30ef66241
2 changed files with 12 additions and 1 deletions

View File

@@ -7,6 +7,10 @@
grid-area: list;
a {
@apply block truncate py-1 px-1 cursor-pointer;
&.active{
// mx-1 外边距
@apply bg-blue-700 text-white mx-1 rounded-md;
}
}
}
.content{

View File

@@ -1,8 +1,15 @@
import { NavLink, Outlet, useLoaderData } from "react-router-dom"
import { NavLink, Outlet, useLoaderData, useNavigate } from "react-router-dom"
import "./content.scss"
import { useEffect } from "react"
export const ContentList = () => {
const contentList = useLoaderData() as ContentType[]
const navigate = useNavigate()
useEffect(() => {
if (contentList) {
navigate(`/config/category/contentList/${contentList[0].category_id}/content/${contentList[0].id}`)
}
}, [contentList])
return (<main className="content-page">
<div className="list">
{contentList.map(content => (