Reputation: 1905
When I use router.navigate() or navigateByUrl(), I get a reload - a
call to the root. The Chrome Dev tools console shows
Navigated to http://localhost/
Navigation via links with
<a [routerLink]=
works correctly.
this.router.navigateByUrl('/test1/test11');
angular-cli: 1.0.0-beta.28.3
node: 7.5.0
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/compiler-cli: 2.4.7
Is published to GitHub, published to GitHub
https://github.com/michaelkariv/angular_router_demo
serve --host localhost --port 80 --live-reload false -prod
Upvotes: 0
Views: 5550
Reputation: 62
As per your code, when anchor clicked it will trigger browser's default navigation
<a href="" (click)="goToTest11()"> router.navigateByUrl('../test1/test11')</a>
to fix that use event.preventDefault()
<a href="" (click)="$event.preventDefault();goToTest11();"> router.navigateByUrl('../test1/test11')</a>
Upvotes: 1
Reputation: 299
I haven't seen your code so this is just a guess, but I think you have missed router-outlet in your app.component.html
<div>
<router-outlet></router-outlet>
</div>
Add the above code to your app.component.html file in the end
Upvotes: 0