简体   繁体   English

下拉菜单中导航栏中的RouterLink不起作用(Angular和Springboot)

[英]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(&quot;/Content/images/bg-home.jpg&quot;) !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.

相关问题 用于编辑类别的下拉菜单不起作用 - Dropdown menu for editing categories doesn't work SpringBoot @Scheduled 不起作用 - SpringBoot @Scheduled doesn't work Bootstrap下拉菜单不起作用 - Bootstrap dropdown menu doen't work 使用websocket进行springboot junit测试时,它不起作用 - springboot junit test when use websocket , it doesn't work 为什么在 aws elasticbeanstalk 上登录我的 springboot 应用程序不起作用? - Why doesn't work logging in my springboot app on aws elasticbeanstalk? SpringBoot 2.2.2:用于自定义分页的 Jackson 序列化程序不起作用 - SpringBoot 2.2.2: Jackson serializer for custom pagination doesn't work 除非输入hello,否则Springboot不起作用 - Springboot doesn't work except when hello is typed 带有 LocalDateTime 的 SpringBoot2 @DateTimeFormat 注释无法按我预期的那样工作 - SpringBoot2 @DateTimeFormat annotation with LocalDateTime doesn't work as i expected Redis 缓存指标在 SpringBoot 版本 2.4.2 中不起作用 - Redis cache metrics doesn't work in SpringBoot version 2.4.2 SpringSecurity 自定义登录功能不适用于 SpringBoot 和 REST api - SpringSecurity custom login functionality doesn't work with SpringBoot and REST api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM