Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Contact link does not work properly in the footer #38

Closed
12 changes: 1 addition & 11 deletions components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,7 @@ export default function Header(props: { fixed?: boolean }) {
<Link
href={item.page + "#" + item.id}
className={className}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (path === item.page) {
document
.getElementById(item.id)
?.scrollIntoView({ behavior: "smooth" });
} else {
router.push(item.page + "#" + item.id);
}
}}
scroll={false}
>
{item.content}
</Link>
Expand Down
14 changes: 13 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @next/next/no-img-element */
import { useState } from "react";
import { useEffect, useState } from "react";
import {
ArrowPathIcon,
ChevronRightIcon,
Expand All @@ -16,6 +16,7 @@ import Link from "next/link";
import CommitLayout from "@/components/Commit/CommitLayout";
import Header from "@/components/header";
import Footer from "@/components/Footer";
import { useRouter } from "next/router";

const primaryFeatures = [
{
Expand Down Expand Up @@ -147,6 +148,17 @@ type Banner = {
href: string;
};
export default function Home() {
const router = useRouter();

if (router.asPath.includes("#")) {
const hash = router.asPath.split("#")[1];
setTimeout(() => {
const targetElement = document.getElementById(hash);
if (targetElement) {
targetElement.scrollIntoView({ behavior: "smooth" });
}
}, 500);
}

const [banner, setBanner] = useState<Banner | null>(null);

Expand Down