开发者

the anchor in javascript does not work correctly

开发者 https://www.devze.com 2022-12-07 18:02 出处:网络
Playback Steps: In the header, click on any of the links with anchors: ##bankaccount #pack #platform #acq ##scorecard

Playback Steps:

In the header, click on any of the links with anchors: ##bankaccount #pack #platform #acq ##scorecard ##intrade #form Scroll the page to the top Reload the page Actual result:

When reloading a page with an anchor in the url, there is no scrolling to the block.

Expected result:

When a page with an anchor in the url is reloaded, a scroll to the block occurs.

The problem is that while the page is not fully loaded, the scroll works, but when the page is fully loaded, the scroll goes back up

import React from 'react';

const useScrollToLocation = () => {
    React.useEffect(() => {
       开发者_C百科 const hash = window.location.hash;
        const id = hash.replace('#', '');
        const element = document.getElementById(id);
        window.location.hash = '';
        if (element) {
            window.location.hash = id;
        }
    }, []);
};
export default useScrollToLocation;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号