Advertisement
Guest User

Angular Dart 2 routing

a guest
Mar 9th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.70 KB | None | 0 0
  1. import 'package:angular2/angular2.dart';
  2. import 'package:angular2/router.dart';
  3.  
  4. @Component(
  5.     selector: 'routing-page')
  6. @View(directives: const [RouterLink, RouterOutlet],
  7.     template: '<div>RoutingPage</div>'
  8.       '<a [routerLink]="[\'Project\', {\'idProject\': \'1\'}]">Project 1 </a>'
  9.       '<a [routerLink]="[\'Project\', {\'idProject\': \'2\'}]">Project 2 </a>'
  10.       '<a [routerLink]="[\'Project\', {\'idProject\': \'3\'}]">Project 3 </a>'
  11.       '<router-outlet></router-outlet>')
  12. @RouteConfig(const [
  13.   const Route(path: '/help', component: HelpPage, name: 'HelpPage'),
  14.   const Route(path: '/project/:idProject/...', component: ProjectPage, name: 'Project'),
  15.   const Route(path: '/', component: HomePage, name: 'Default', useAsDefault: true)
  16. ])
  17. class RoutingPage
  18. {
  19. }
  20.  
  21. @Component(selector: 'home-page')
  22. @View(template: '<div>Home Page</div>')
  23. class HomePage
  24. {
  25. }
  26.  
  27. @Component(selector: 'help-page')
  28. @View(template: '<div>Help page</div>')
  29. class HelpPage
  30. {
  31. }
  32.  
  33. @Component(selector: 'project-page')
  34. @View(directives: const [RouterLink, RouterOutlet],
  35.     template: '<div>Project page. Project: {{idProject}}</div>'
  36.   '<a [routerLink]="[\'Year\', {\'idYear\': \'2013\'}]">2013 </a>'
  37.   '<a [routerLink]="[\'Year\', {\'idYear\': \'2014\'}]">2014 </a>'
  38.   '<a [routerLink]="[\'Year\', {\'idYear\': \'2015\'}]">2015 </a>'
  39.   '<router-outlet></router-outlet>')
  40. @RouteConfig(const [
  41.   const Route(path: '/year/:idYear/...', component: YearPage, name: 'Year'),
  42.   const Route(path: '/', component: ProjectDefaultPage, name: 'Default', useAsDefault: true)
  43. ])
  44. class ProjectPage implements CanReuse, OnReuse
  45. {
  46.   String idProject;
  47.  
  48.   ProjectPage(RouteParams params)
  49.   {
  50.     idProject = params.get("idProject");
  51.   }
  52.  
  53.   dynamic routerCanReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  54.   {
  55.     return true;
  56.   }
  57.  
  58.   dynamic routerOnReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  59.   {
  60.     return true;
  61.   }
  62. }
  63.  
  64. @Component(selector: 'project-default-page')
  65. @View(template:'<div>Default project page</div>')
  66. class ProjectDefaultPage
  67. {
  68. }
  69.  
  70. @Component(selector: 'year-page')
  71. @View(directives: const [RouterLink, RouterOutlet],
  72.     template: '<div>Year page. Year: {{idYear}}</div>'
  73.   '<a [routerLink]="[\'Month\', {\'idMonth\': \'1\'}]">1 </a>'
  74.   '<a [routerLink]="[\'Month\', {\'idMonth\': \'2\'}]">2 </a>'
  75.   '<a [routerLink]="[\'Month\', {\'idMonth\': \'3\'}]">3 </a>'
  76.   '<router-outlet></router-outlet>')
  77. @RouteConfig(const [
  78.   const Route(path: '/month/:idMonth', component: MonthPage, name: 'Month'),
  79.   const Route(path: '/', component: YearDefaultPage, name: 'Default', useAsDefault: true)
  80. ])
  81. class YearPage implements CanReuse, OnReuse
  82. {
  83.   String idYear;
  84.  
  85.   YearPage(RouteParams params)
  86.   {
  87.     idYear = params.get("idYear");
  88.   }
  89.  
  90.   dynamic routerCanReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  91.   {
  92.     return true;
  93.   }
  94.  
  95.   dynamic routerOnReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  96.   {
  97.     return true;
  98.   }
  99. }
  100.  
  101. @Component(selector: 'year-default-page')
  102. @View(template:'<div>Default Year page</div>')
  103. class YearDefaultPage
  104. {
  105. }
  106.  
  107. @Component(selector: 'month-page')
  108. @View(template:'<div>Month page. Month: {{idMonth}}</div>')
  109. class MonthPage implements CanReuse, OnReuse
  110. {
  111.   String idMonth;
  112.   MonthPage(RouteParams params)
  113.   {
  114.     idMonth = params.get("idMonth");
  115.   }
  116.  
  117.   dynamic routerCanReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  118.   {
  119.     return true;
  120.   }
  121.  
  122.   dynamic routerOnReuse(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction)
  123.   {
  124.     return true;
  125.   }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement