Created
September 18, 2017 20:24
-
-
Save kshep92/6bea433b40982879b28c42f3228c851f to your computer and use it in GitHub Desktop.
Routing with Page.js + Polymer
This file contains hidden or 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
<iron-pages selected="[[selected]]"> | |
<home-page name="home"></home-page> | |
<contacts-page name="contacts"></contacts-page> | |
<admin-page name="admin"></admin-page> | |
</iron-pages> | |
<script> | |
// ...Polymer boilerplate | |
{ | |
properties: { | |
selected: String, | |
value: function() { return 'home' } | |
} | |
page('/', (ctx) => this.selected = 'home' ); | |
page('/contacts', (ctx) => this.selected = 'contacts' ); | |
page('/admin/*', checkAuth, () => this.selected = 'admin' ); | |
function checkAuth(ctx, next) { | |
if(userIsAdmin) next(true) | |
else page.redirect('/unauthorized') | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment