-
-
Save funky-jojo/4afa87681ff95a3c043ab65e954c38d2 to your computer and use it in GitHub Desktop.
Aurelia Router CanActivate Demo
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> | |
<require from="components/navigation.html"></require> | |
<h1>Aurelia Router CanActivate Redirect Bug Demo</h1> | |
<p> | |
Repro steps: | |
</p> | |
<ol> | |
<li>Load the page with settings as the specified route: <a target="_blank" href="https://gist.host/run/1483977856446/index.html#/settings">https://gist.host/run/1483977856446/index.html#/settings</a></li> | |
<li>Click "Cancel" on the confirm dialog. This will redirect to the 'home' route.</li> | |
<li>Click "Settings" menu. Click "Cancel" on the confirm dialog. This will cancel the navigation, and remain on the current route.</li> | |
<li>Click "Settings" menu again. This time, nothing happens, because the router is now in a inconsistent state.</li> | |
</ol> | |
<navigation router.bind="router" class="primary-navigation"></navigation> | |
<div class="page-host"> | |
<router-view></router-view> | |
</div> | |
</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
export class App { | |
configureRouter(config, router) { | |
config.title = 'Aurelia'; | |
config.map([ | |
{route: ['', 'home'], name: 'home', moduleId: 'home/home', nav: true, title: 'Home'}, | |
{route: 'settings', name: 'settings', moduleId: 'settings/settings', nav: true, title: 'Settings'} | |
]); | |
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
<template> | |
<h2>Home</h2> | |
</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
export class Home { | |
} |
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> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body aurelia-app="main"> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.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
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin('aurelia-dialog'); | |
aurelia.start().then(() => 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
<template> | |
<h2>Settings</h2> | |
</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, Redirect } from 'aurelia-router'; | |
import { inject } from 'aurelia-framework'; | |
@inject(Router) | |
export class Settings { | |
constructor(router:Router){ | |
this.router = router; | |
} | |
canActivate(){ | |
return new Promise((resolve, reject) => { | |
if ( confirm("Click Cancel to see the bug in action.") ){ | |
resolve(true); | |
}else{ | |
var history: any = this.router.history; | |
//stay on current page, if there is one, | |
// otherwise, redirect to home route | |
if (history.previousLocation) { | |
reject(false); | |
} else { | |
resolve(new Redirect("home")); | |
} | |
} | |
}); | |
} | |
} |
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
:root { | |
--accent: rgba(236,12,104,.8); | |
--white: #fff; | |
--light-grey: #666; | |
--medium-grey: #444; | |
--dark-grey: #333; | |
--default-border-width: 1px; | |
--default-border-color: #eee; | |
--default-border: var(--default-border-width) solid var(--default-border-color); | |
--page-host-border-color: var(--default-border-color); | |
--page-host-border-width: var(--default-border-width); | |
--navigation-bgc: var(--light-grey); | |
--navigation-item-hover-bgc: var(--medium-grey); | |
--navigation-item-active-bgc: var(--accent); | |
--navigation-item-border-color: var(--default-border-color); | |
} | |
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
body { | |
padding: 1em; | |
font-family: sans-serif; | |
} | |
ul { | |
overflow: hidden; | |
list-style-type: none; | |
} | |
a { | |
display: inline-block; | |
text-decoration: none; | |
} | |
.page-host { | |
margin-top: .5em; | |
padding: 1em; | |
border: var(--default-border); | |
} | |
.primary-navigation, | |
.secondary-navigation { | |
display: block; | |
background-color: var(--navigation-bgc); | |
} | |
.primary-navigation { | |
margin: 1em 0; | |
} | |
.primary-navigation li:not(.active):hover, | |
.secondary-navigation li:not(.active):hover { | |
background-color: var(--navigation-item-hover-bgc); | |
} | |
.primary-navigation li, | |
.secondary-navigation li, | |
.tertiary-navigation li { | |
float: left; | |
border-right: var(--default-border-width) solid var(--navigation-item-border-color); | |
} | |
.tertiary-navigation li { | |
padding: 0 .5em; | |
} | |
.tertiary-navigation li:first-child { | |
padding-left: 0; | |
} | |
.tertiary-navigation li:last-child { | |
border-right: none; | |
} | |
.primary-navigation a, | |
.secondary-navigation a { | |
color: var(--white); | |
} | |
.tertiary-navigation a { | |
color: var(--dark-grey); | |
} | |
.primary-navigation a { | |
padding: 1em 2em; | |
} | |
.secondary-navigation a { | |
padding: .5em 1em; | |
} | |
.primary-navigation .active , | |
.secondary-navigation .active { | |
background-color: var(--navigation-item-active-bgc); | |
} | |
.tertiary-navigation .active { | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment