Skip to content

Commit

Permalink
refactor(theme): keep scroll position after browser navigated
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Nov 26, 2020
1 parent f95a790 commit 1611012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/preset-dumi/src/theme/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export const LinkWrapper = (Component: React.FC<LinkProps | NavLinkProps>) => {
: undefined
}
{...props}
{...(isExternal ? {} : {
// scroll to top while change url
onClick(...args) {
window.scrollTo({
top: 0,
});
props.onClick?.apply(this, args);
}
})}
/>
);
};
Expand Down
7 changes: 0 additions & 7 deletions packages/theme-default/src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ const Layout: React.FC<IRouteComponentProps> = ({ children, location }) => {
(repoUrl || '').match(/(github|gitlab)/)?.[1] || 'nothing'
];

// set scroller to top while change url
useEffect(() => {
window.scrollTo({
top: 0,
});
}, [location.pathname]);

return (
<div
className="__dumi-default-layout"
Expand Down

0 comments on commit 1611012

Please sign in to comment.