Angular 2 application reload when changing route

I have an angular 2 application with the following routes:

@RouteConfig([
new Route({ path: '/', component: Home, name: 'Home', useAsDefault: true}),
new Route({ path: '/employees', component: ViewEmployees, name: 'ViewEmployees'}),
new Route({ path: '/employees/add', component: AddEmployee, name: 'AddEmployee'}),
])

among others. When I change routes as follows:

<a [routerLink]="['ViewEmployees']">View Employees</a>

No problems. I can change routes this way either from the main page or from the AddEmployee route. The problem occurs when I am on the AddEmployee path and trying to change routes programmatically as follows:

import {Router} from 'angular2/router';
...
constructor(private _router:Router) {}
...
navigate() {
    this._router.navigate(['ViewEmployees']);
}

he does not work. It sends me to the ViewEmployees view and then reloads the entire application. If I make the same change in program routes from the Home component, I have no problem; the application does not restart.

- , ? , , , .

!

+4
3

navigate() <form>?

. , Angular2s GitHub, , . , router.navigate() , . , ? URL- .

: return false navigate(). , . angular , .

+2

RouterLink docs:

/,./../. /, . . /, . . /, .

:

<a [routerLink]="['/ViewEmployees']">View Employees</a>
0

<base href>?

Add the following code to your index.htmlafter opening the tag head:

<base href="/">

0
source

All Articles