Skip to content

Instantly share code, notes, and snippets.

@kshep92
Created September 18, 2017 20:24
Show Gist options
  • Save kshep92/6bea433b40982879b28c42f3228c851f to your computer and use it in GitHub Desktop.
Save kshep92/6bea433b40982879b28c42f3228c851f to your computer and use it in GitHub Desktop.
Routing with Page.js + Polymer
<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