I am using react Next js Link element:
import Link from 'next/link';
and also some buttons in my app that scroll to an element when clicked using:
import { Link } from 'react-scroll';
https://www.npmjs.com/package/react-scroll
Both work good separate, But I have one Link that go to another page and I want to scroll after: The link should work like that:
- if the user is on the page that this link should link to - it should only scroll to the element.
- if the user is on any other page, the link should change page and then scroll to the element.
How can I catch page changes and know if this link was clicked then scroll? Or any other way to solve it?