-
-
Save JontyMC/2932e615bffdd8f7c4b9735d9efd36b7 to your computer and use it in GitHub Desktop.
Aurelia SetRoot
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.4.6/bluebird.min.js"></script> | |
</head> | |
<body aurelia-app="src/main"> | |
<script src="https://cdn.rawgit.com/aurelia/aurelia/master/scripts/system.js"></script> | |
<script src="https://cdn.rawgit.com/aurelia/aurelia/master/scripts/config-typescript.js"></script> | |
<script src="https://cdn.rawgit.com/aurelia/aurelia/master/scripts/aurelia-core.min.js"></script> | |
<script src="https://cdn.rawgit.com/aurelia/aurelia/master/scripts/aurelia-routing.min.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
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
<template> | |
<button click.delegate="logout()"></button> | |
</template> |
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 {Router, RouterConfiguration, Redirect} from 'aurelia-router'; | |
import {autoinject} from 'aurelia-framework'; | |
import {AuthorizeStep} from './auth/authorize-step'; | |
export class App { | |
public configureRouter(config: RouterConfiguration, router: Router) { | |
config.addPipelineStep('authorize', AuthorizeStep); | |
config.map([ | |
{ route: ['', 'home'], name: 'home', moduleId: 'home', title: 'home'}, | |
]); | |
this.router = router; | |
} | |
} |
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 {Router, RouterConfiguration, Redirect} from 'aurelia-router'; | |
import {autoinject} from 'aurelia-framework'; | |
import {AuthorizeStep} from './auth/authorize-step'; | |
export class Auth { | |
public configureRouter(config: RouterConfiguration, router: Router) { | |
config.addPipelineStep('authorize', AuthorizeStep); | |
config.map([ | |
{ route: ['', 'login'], name: 'login', moduleId: 'login', title: 'login'}, | |
{ route: 'register', name: 'register', moduleId: 'register', title: 'register'} | |
]); | |
this.router = router; | |
} | |
} |
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
export class AuthService { | |
loggedIn = false; | |
login() { | |
this.loggedIn = | |
} | |
logout() { | |
this.loggedIn = false; | |
this.router.navigate('/', { replace: true, trigger: false}); | |
this.router.reset(); | |
this.router.deactivate(); | |
await this.aurelia.setRoot('auth/auth'); | |
} | |
} |
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
export function configure(aurelia) { | |
aurelia.use.basicConfiguration(). | |
aurelia.start().then(() => aurelia.setRoot('auth/auth')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment