I can’t detect #
hash code changes in URL with any of the useRouter
props as useEffect
dependancy:
const { locale, asPath, basePath, pathname, route, query } = useRouter();
const [hashCode, setHashCode] = useState<number>(1);
useEffect(() => {
console.log("Hash code changed");
if (asPath.split("#")) setHashCode(Number(asPath.split("#")[1]));
else {
setHashCode(1);
}
}, [asPath, pathname, basePath, route, query]);
return (
<>
<a href="1">
Hash code 1
</a>
<a href="2">
Hash code 2
</a>
</>
How can I detect hash code in the URL has been changed and set the current hash code in a state with Next JS ?