[英]RouterLink inside a navbar in a dropdown menu doesn't work (Angular and Springboot)
i must develop a web App using spring boot and angular. 我必须使用spring boot和angular开发一个Web App。 In this app there is a tab which contains various data (connect with mongoDB).i created a component for add new data in this tab.
在此应用程序中,有一个包含各种数据的标签(与mongoDB连接)。我在此标签中创建了一个用于添加新数据的组件。 The problem is when i try to press a link in a dropdown menu inside the navbar doesn't redirect me in the correct page but show me whitelabel page
问题是,当我尝试按导航栏内的下拉菜单中的链接时,无法在正确的页面中重定向我,但显示白色标签页面
i tried to use routerLink and href, delete the dropdown and using a button in a navbar. 我尝试使用routerLink和href,删除下拉菜单并使用导航栏中的按钮。 i added the navar first in my index.html, then i tried inside app.component.
我先在index.html中添加了navar,然后在app.component中尝试了。
my index.html 我的index.html
/* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunction() { document.getElementById("myDropdown").classList.toggle("show"); } // Close the dropdown if the user clicks outside of it window.onclick = function(e) { if (!e.target.matches('.dropbtn')) { var myDropdown = document.getElementById("myDropdown"); if (myDropdown.classList.contains('show')) { myDropdown.classList.remove('show'); } } }
<header> <div id="riga-top"></div> <nav id="navbar"> <div id="area-logo-universita"> <img src="assets/img/logo-unicam.jpg"> </div> <div id="area-logo-servizio"> <img src=""> </div> <ul> <li class="active collapse"> <a href="/contatto">HOME</a> </li> <li class="dropdown collapse"> <button class="dropbtn" onclick="myFunction()">Aziende <span class="caret"></span> </button> <div class="dropdown-menu dropdown-content" id="myDropdown"> <a href="/azienda" class="ainside">Aggiungi Azienda</a> </div> </li> </nav> </header> <!-- Left side column. contains the logo and sidebar --> <div class="content-wrapper" style="background-color: rgb(236, 240, 245) !important; background-image: url("/Content/images/bg-home.jpg") !important; background-repeat: no-repeat !important; min-height: 710px;"> <div class="container"> <!-- Main content --> <section class="content"> <app-root></app-root> </section><!-- /.content --> </div> </div> <footer> </footer>
You have to implement Router Link like below and should not use href, you can find complete documentation here. 您必须实现如下所示的Router Link,并且不应使用href,您可以在此处找到完整的文档。
Replace following 替换以下
<li class="active collapse">
<a href="/contatto">HOME</a>
</li>
By this 这样
<li class="active collapse">
<a [routerLink]="['/contatto']">
HOME
</a>
</li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.