Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!