Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda