Display Warning for Unsaved Form Data on Page Exit

I’m unable to prevent navlink to warn before redirect to new url. and unable to reload same link
React-router-dom v6.4
react v18 with typescript.

<NavLink to={menuItem.getRoute()} </NavLink>