Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
190 lines (164 sloc) 5.91 KB
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
The complete set of authors may be found at
The complete set of contributors may be found at
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
<link rel="import" href="../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../bower_components/app-layout/app-scroll-effects/app-scroll-effects.html">
<link rel="import" href="../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../bower_components/app-route/app-location.html">
<link rel="import" href="../bower_components/app-route/app-route.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="my-icons.html">
<dom-module id="my-app">
:host {
--app-primary-color: #4285f4;
--app-secondary-color: black;
display: block;
app-drawer-layout:not([narrow]) [drawer-toggle] {
display: none;
app-header {
color: #fff;
background-color: var(--app-primary-color);
app-header paper-icon-button {
--paper-icon-button-ink-color: white;
.drawer-list {
margin: 0 20px;
.drawer-list a {
display: block;
padding: 0 16px;
text-decoration: none;
color: var(--app-secondary-color);
line-height: 40px;
.drawer-list a.iron-selected {
color: black;
font-weight: bold;
<app-location route="{{route}}" url-space-regex="^[[rootPath]]"></app-location>
<app-drawer-layout fullbleed>
<!-- Drawer content -->
<app-drawer id="drawer" slot="drawer">
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="view1" href$="[[rootPath]]view1">View One</a>
<a name="view2" href$="[[rootPath]]view2">View Two</a>
<a name="view3" href$="[[rootPath]]view3">View Three</a>
<a name="view4" href$="[[rootPath]]view4">View Four</a>
<!-- Main content -->
<app-header-layout has-scrolling-region>
<app-header slot="header" condenses reveals effects="waterfall">
<paper-icon-button icon="my-icons:menu" drawer-toggle></paper-icon-button>
<div main-title>My App</div>
<my-view1 name="view1"></my-view1>
<my-view2 name="view2"></my-view2>
<my-view3 name="view3"></my-view3>
<my-view404 name="view404"></my-view404>
class MyApp extends Polymer.Element {
static get is() { return 'my-app'; }
static get properties() {
return {
page: {
type: String,
reflectToAttribute: true,
observer: '_pageChanged',
routeData: Object,
subroute: String,
rootPath: {
type: String,
value: '/'
lazyPages: {
type: Object,
value: {
view1: function() {
import(/* webpackChunkName: "my-view1" */ './my-view1.html');
view2: function() {
import(/* webpackChunkName: "my-view2" */ './my-view2.html');
view3: function() {
import(/* webpackChunkName: "my-view3" */ './my-view3.html');
view404: function() {
import(/* webpackChunkName: "my-view404" */ './my-view404.html');
static get observers() {
return [
constructor() {
_routePageChanged(page) {
// Polymer 2.0 will call with `undefined` on initialization.
// Ignore until we are properly called with a string.
if (page === undefined) {
// If no page was found in the route data, page will be an empty string.
// Deault to 'view1' in that case. = page || 'view1';
// Close a non-persistent drawer when the page & route are changed.
if (!this.$.drawer.persistent) {
_pageChanged(page) {
} else {
_showPage404() { = 'view404';
window.customElements.define(, MyApp);
You can’t perform that action at this time.