Created
December 22, 2016 06:39
-
-
Save kulshekhar/376b547133faa3afeb74fb2c15b26c78 to your computer and use it in GitHub Desktop.
AngularDart sample using CanActivate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:html'; | |
import 'package:angular2/core.dart'; | |
import 'package:angular2/router.dart'; | |
@Component( | |
selector: 'my-app', | |
styleUrls: const ['app_component.css'], | |
template: ''' | |
<h1>My First Angular 2 App</h1> | |
<div> | |
<a [routerLink]="['Home']">home</a> - | |
<a [routerLink]="['General']">general area</a> - | |
<a [routerLink]="['Secret']">secret area</a> | |
</div> | |
<router-outlet></router-outlet> | |
''', | |
directives: const [ROUTER_DIRECTIVES], | |
providers: const [ROUTER_PROVIDERS], | |
) | |
@RouteConfig(const [ | |
const Route( | |
path: '/', name: 'Home', component: HomeComponent, useAsDefault: true), | |
const Route(path: '/secret', name: 'Secret', component: SecretComponent), | |
const Route(path: '/general', name: 'General', component: GeneralComponent), | |
]) | |
class AppComponent {} | |
@Component( | |
selector: 'secret-area', | |
template: '<div>Welcome to the secret area</div>', | |
) | |
@CanActivate(secretValidator) | |
class SecretComponent {} | |
secretValidator(ComponentInstruction next, ComponentInstruction prev) { | |
if (prev.routeName == 'General') return true; | |
window.alert('Unauthorized'); | |
} | |
@Component( | |
selector: 'general-area', | |
template: '<div>Welcome to the general area</div>', | |
) | |
class GeneralComponent {} | |
@Component( | |
selector: 'm-home', | |
template: '<div>Welcome</div>', | |
) | |
class HomeComponent {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment