Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
Why <a href='#'> refresh the whole page in Angular 4

I am learning Angular 4.0 from this tutorial on its website. I can run the sample, but meet the problem in my project when I want to add a to simulate a dropdown list using boostarp. Let's look the details:

app-routing.module.ts:

const routes: Routes = [
{ path: '', redirectTo: 'mission', pathMatch: 'full' },
{ path: 'user', component: SlUserPanelComponent },
{ path: 'mission', component: SlMissionPanelComponent }
]
@NgModule({
    imports: [ RouterModule.forRoot(routes) ],
    exports: [ RouterModule ]
})
export class AppRoutingModule {}

when type 'http ://localhost:3000' in browser, the page will redirect to 'http ://localhost:3000/mission' and show everything.

Then I add following code to the html corresponding to '/mission', and click the hyperlink, the browser will come back to 'http ://localhost:3000' and redirect to 'http ://localhost:3000/mission' again. That is not my expection, as my understand, it should not refresh the page and just show the dropdown list after click.

<div class="collapse navbar-collapse">
  <ul class="nav navbar-nav navbar-left">
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">
        <i class="fa fa-globe"></i>
        <b class="caret"></b>
        ......
      </a>
    </li>
    <li>
    </li>
  </ul>
</div>

I don't know why and how to fix the problem.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

As you are can see any angular application will have a path as

http://localhost:3000/#/home

When you are using

<a href="#">

Your path will be navigated to

http:localhost/3000/#/home#

which is a new route and angular tries to map this route to any available routes . so your app refreshes

over 4 years ago · Santiago Trujillo Denunciar

0

Following should work
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda