feat(website): drop hash-based router
This commit is contained in:
@@ -23,7 +23,7 @@ export default function Header() {
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
{/* Logo */}
|
||||
<Link
|
||||
href="~/"
|
||||
href="/"
|
||||
className="flex items-center gap-2 sm:gap-3 group shrink-0"
|
||||
aria-label={isZh ? 'page-agent 首页' : 'page-agent home'}
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
@@ -56,7 +56,7 @@ export default function Header() {
|
||||
aria-label="Mobile navigation"
|
||||
>
|
||||
<Link
|
||||
href="~/docs/introduction/overview"
|
||||
href="/docs/introduction/overview"
|
||||
className="p-2 rounded-lg text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 shrink-0"
|
||||
aria-label={isZh ? '文档' : 'Docs'}
|
||||
>
|
||||
@@ -90,7 +90,7 @@ export default function Header() {
|
||||
{import.meta.env.VERSION}
|
||||
</span>
|
||||
<Link
|
||||
href="~/docs/introduction/overview"
|
||||
href="/docs/introduction/overview"
|
||||
className="flex items-center gap-1.5 text-gray-600 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200"
|
||||
>
|
||||
<BookOpen className="w-4 h-4" />
|
||||
@@ -138,7 +138,7 @@ export default function Header() {
|
||||
role="navigation"
|
||||
>
|
||||
<Link
|
||||
href="~/docs/introduction/overview"
|
||||
href="/docs/introduction/overview"
|
||||
className="flex items-center gap-2 px-3 py-2 rounded-lg text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
>
|
||||
|
||||
37
packages/website/src/components/Heading.tsx
Normal file
37
packages/website/src/components/Heading.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ComponentPropsWithoutRef, useEffect, useRef } from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
type Level = 2 | 3
|
||||
|
||||
interface HeadingProps extends Omit<ComponentPropsWithoutRef<'h2'>, 'children'> {
|
||||
id: string
|
||||
level: Level
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
const tags = { 2: 'h2', 3: 'h3' } as const
|
||||
|
||||
export function Heading({ id, level, className, children, ...props }: HeadingProps) {
|
||||
const ref = useRef<HTMLHeadingElement>(null)
|
||||
const Tag = tags[level]
|
||||
|
||||
useEffect(() => {
|
||||
if (window.location.hash === `#${id}`) {
|
||||
ref.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
}, [id])
|
||||
|
||||
return (
|
||||
<Tag ref={ref} id={id} className={cn('group relative scroll-mt-20', className)} {...props}>
|
||||
<a
|
||||
href={`#${id}`}
|
||||
className="absolute -left-5 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 text-gray-400 hover:text-blue-500 transition-opacity no-underline"
|
||||
aria-label={`Link to ${id}`}
|
||||
>
|
||||
#
|
||||
</a>
|
||||
{children}
|
||||
</Tag>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user