【发布时间】:2021-06-18 08:18:45
【问题描述】:
I'm developing a website where I have a navbar at the top, and when an option is selected, the screen goes to the part of the page that is linked with the ID.我的问题是,一旦我按下该选项,URL 就会显示 # + 所选选项。如何删除 # 并只留下单词,或者是否可以选择删除两者。我没有使用 React-ROUTER-DOM
发生了什么:www.mywebsite.com/#aboutus
我想发生什么:www.mywebsite.com/aboutus 或只是www.mywebsite.com
导航栏
<div className="main-navbar">
<a href="#home">home</a>
<a href="#aboutus">about</a>
<a href="#contact">contact</a>
</div>
示例
<div id="aboutus">
//CONTENT
< /div>
【问题讨论】:
-
你能去掉锚标签上的“#”号吗?
-
删除
#将产生服务器端后果。如果您使用修改后的 url 重新加载页面,则服务器不知道该路径。服务器看不到哈希部分 (#xxxx) -
如果我这样做,它不会进入我想要的页面部分,它只会刷新网站
标签: javascript reactjs linker href