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.
- , ? , , , .
!