Created
September 9, 2016 21:00
-
-
Save martonsagi/c8bdb291aa052ee92b4a1403e4ac10d1 to your computer and use it in GitHub Desktop.
Permission check on two routes with the same module
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> | |
<div class="container-fluid"> | |
<h4 class="page-header">Permission check on two routes with the same module</h4> | |
<a class="btn btn-primary" href="#/route1">Route #1</a> | |
<a class="btn btn-danger" href="#/route2">Route #2</a> | |
<div class="panel"> | |
<div class="panel-body"> | |
<router-view></router-view> | |
</div> | |
</div> | |
</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
import {Redirect} from 'aurelia-router'; | |
export class App { | |
configureRouter(config, router) { | |
config.options.pushState = false; | |
config.map([ | |
{ | |
"route": ["", "route1"], | |
"name": "route1", | |
"moduleId": "same-route", | |
"nav": true, | |
"title": "Route #1" | |
}, | |
{ | |
"route": "route2", | |
"name": "route2", | |
"moduleId": "same-route", | |
"nav": true, | |
"title": "Route #2" | |
}, | |
{ | |
"route": "unauthorized", | |
"name": "unauthorized", | |
"moduleId": "unauthorized", | |
"nav": true, | |
"title": "Error" | |
} | |
]); | |
config.addPipelineStep('authorize', AuthorizeStep); | |
this.router = router; | |
} | |
} | |
class AuthorizeStep { | |
run(navigationInstruction, next) { | |
if (navigationInstruction.config.name !== "unauthorized") { | |
var hasPermission = navigationInstruction.config.name === "route1"; | |
if (!hasPermission) { | |
return next.cancel(new Redirect('unauthorized')); | |
} | |
} | |
return next(); | |
} | |
} |
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 href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['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> | |
Shared view ${message} | |
</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 SameRoute { | |
message = Date.now(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment