Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 717 Bytes

using_the_router_programmatically.md

File metadata and controls

23 lines (19 loc) · 717 Bytes

Using the Router Programmatically

In addition to being able to use the routerLink directive to control the navigation of your application, you can also access the router from your components using the Router service. To do this you must inject the router into your component as shown:

// ...
@Component({
  selector: 'component-one',
  template: `Component One<br/>
  <button (click)="onClick()">Click Me</button>
  `
})
export default class ComponentOne { 
  constructor(private _router:Router) { 
    
  }
  onClick () {
    this._router.navigate(['/ComponentThree',{message: 'Called from _router.Navigate'}]);
  }
}

View Example