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

Same link clicked again don't redirect again to the ref. #434

Open
bastek338 opened this issue Nov 4, 2022 · 1 comment
Open

Same link clicked again don't redirect again to the ref. #434

bastek338 opened this issue Nov 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@bastek338
Copy link

First of all I would like to thank you for this library, good job!

Issue
When i click for the first time on the link, a scroll redirect to the desired place and it works like a charm.
But when i go again to my clicked link and i try to trigger scroll func again which should redirect into desired hash related component - nothing happens.

I know it may be related to the fact that I currently have the same hash in our url path.

Maybe we can create some function which removes hash from the url. This option might be set as false by default.

My current workaround for this problem is:

const location = useLocation();
const history = useHistory();

  useEffect(() => {
	let timer;
	if (location.hash) {
	   timer = setTimeout(() => {
		history.replace(location.pathname);
	   }, 1000);
	}
	return () => {
		clearTimeout(timer);
	};
  }, [location.hash]
@bastek338 bastek338 added the bug Something isn't working label Nov 4, 2022
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

Thank you for contributing to React Hash Scroll!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant