admin管理员组文章数量:1288010
I need to deduct the hash change with URL. for that I tried all this way from here:
How to detect change in the URL hash in Next.js?
Nothing works, But if I set Timeout it's working.
useEffect(() => {
setTimeout(() => {
console.log(window && window.location.hash)
},1000)
});
Need to know what's happening or what would be the correct way to handle? though it is working, need to know the background things what is causing.
it's not working
const params = useParams();
const [url, setURL] = useState<string>('')
useEffect(() => {
const update = () => {
// set url from path in forward.
setURL(window.location.href.substring(window.location.href.indexOf('/', 9)))
};
window.addEventListener('hashchange', update);
update(); // Initial fetch
return () => window.removeEventListener('hashchange', update)
}, [params])
console.log(url)
本文标签: nextjs15Nextjs URL hash change only works with quotsetTimeoutquotStack Overflow
版权声明:本文标题:next.js15 - Next.js URL hash change only works with "setTimeout" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741335510a2373015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论