我正在开发一个使用Angularjs和Twitter Bootstrap的项目。
Bootstrap使用#来切换组件,比如弹出框、模态框等,例如:
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
点击带有此href属性的按钮会导致整个页面重新加载,这意味着当前页面中的所有内容都将丢失。 有没有方法可以防止这种情况发生?
一些额外的信息:
当我悬停在按钮上时,URL很奇怪。例如,我的当前页面的URL是
localhost:8080/#/account
按钮的 href 属性为
href="#myModal"
我希望看到URL
localhost:8080/#/account#myModal
然而,我看到的是
localhost:8080/#myModal
我不确定这是否与我的问题有关。
提前感谢!
编辑1
我已经看到了Stewie提到的其他帖子。它解释了AngularJS中的html5mode和hashbang,但并没有真正解决我的问题。
我尝试使用html5mode,但当我点击按钮时它仍会重新加载页面。
<a>
标签,它明确定义了在页面内部导航的语义角色?这不是指向资源的链接,为什么不直接使用<span>
标签呢? - Mike 'Pomax' Kamermansdata-target
选项吗?这样你就可以让 Angular 选择 href。 - Sherbrow