리액트로 프로젝트를 하면 a태그 대신에 Link를 사용하잖아요?
<Link to='/page/about' ></Link>.. 이런식으로요
근데 이건 클릭을해서 페이지를 이동시키면 전 화면의 스크롤위치를 기억해서 그대로 옮겨져오더라구요..
이게 싫을경우
import React, { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { styled } from 'styled-components';
const SLink = styled(Link)``;
interface CustomLinkProps {
children: ReactNode;
to: string;
}
const CustomLink = ({ children, to }: CustomLinkProps) => {
const onLinkClick = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
return (
<SLink to={to} onClick={onLinkClick}>
{children}
</SLink>
);
};
export default CustomLink;
이런식으로해서 컴포넌트로 감싸주면 되나요?