html - Why does refreshing an anchor link / trying to go directly to an anchor link go to the top of the page?
问题描述
I have buttons in a site, and naturally, I've created anchors and links pointing to those anchors. The buttons work, but when I refresh the page or try to go to that specific anchor from a new tab (for instance), it always directs to the top of the page.
(e.g. In the code below, there is a section with id "about". When I click on the button that reads "about" in my nav bar, it changes the url to ".../#about" and goes to that section. However, when I refresh my page with the url ".../#about" or try to go to ".../#about" from a new tab, it always goes to the top of the page (the url doesn't change to "..." though, so it's not redirecting).)
I want the user to be able to go to ".../#about" and go directly to the about section when going from a new tab or different site, but how would I do that? Thanks!
Here's my code (please let me know if there's more you'd like to see):
const Index = () => {
return (
<div>
<Header />
<div className="all-content">
<Hero />
<Social />
<section id="about">
<About />
</section>
<section id="projects">
<Projects />
</section>
<section id="hobbies">
<Hobbies />
</section>
<section id="contact">
<Contact />
</section>
</div>
</div>
);
}
export default Index;
解决方案
推荐阅读
- arrays - 如何在 PL/SQL 中创建 10 个数字的数组并按升序排序
- php - Sagepay 表单集成 3.0,发送徽标
- excel - 通过 ActiveCell 嵌入值的 VBA 宏循环
- docusignapi - ApiClient 方法 RequestJWTUserToken 在哪里?
- angular - Angular 5 - 如何从 HTML 获取变量到组件
- python - 从具有多个值的熊猫系列创建字典
- telegram - 关于电报隐私的一般问题
- sql - 如何在函数内部创建一个不能从外部查看的表?
- c++ - C ++中“Class1 :: Class2”的含义是什么?
- python - 如何转换存储在 pandas 数据框中的图像(numpy 数组)的数据类型?