Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 router examples + @Routes typing support

Tags:

I am trying to find a concrete example on how to use the router in Angular 2. Furthermore the current angular2.d.ts typing file from the 5 min quickstart does not support @Routes annotation.

like image 506
doorman Avatar asked May 06 '15 14:05

doorman


1 Answers

Main component and Class of Routing in Angular 2.

router-link – router-link directive is use to declare link into view . Its can contains optional parameters also.

Example :

<a [router-link]="['/AboutUs']">About Us</a> 

router-outlet – Its work as a placeholder for views to render then component. Means template and templateUrl will be render on that location where you will use router-outlet directive.

Example :

<router-outlet></router-outlet> 

@RouteConfig – We map URLs to components in this section which used inside the .

Example :

@RouteConfig([     {path: '/',        component: HomeComponent, as: 'Home'},     {path: '/aboutus', component: AboutUsComponent, as: 'AboutUs'  }     {path: '/contactus', component: ContactUsComponent, as: 'ContactUs'  } ]) 

RouteParams – Parameter to a component which rendered by the router.

Read this article for more http://www.codeandyou.com/2015/11/understand-routing-in-angular-2.html

like image 163
virender Avatar answered Oct 21 '22 10:10

virender