• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!--
2@license
3Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7Code distributed by Google as part of the polymer project is also
8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9-->
10
11<link rel='import' href='../app-route.html'>
12<link rel='import' href='../app-location.html'>
13
14<dom-module id='app-example-1'>
15  <template>
16    <app-location route='{{route}}'>
17    </app-location>
18    <app-route id="page" route='{{route}}' pattern='/:page' data='{{data}}'>
19    </app-route>
20    <app-route id="user" route='{{route}}' pattern='/user' tail='{{userRoute}}'>
21    </app-route>
22    <app-route id="tail" route='{{userRoute}}' pattern='/:page' data='{{userData}}' query-params="{{userQueryParams}}">
23    </app-route>
24  </template>
25  <script>
26    Polymer({
27      is: 'app-example-1',
28      observers: [
29        'pageChanged(data.page)',
30        'userPathChanged(userRoute.path)',
31      ],
32      pageChanged: function(page) {
33        if (page === 'redirectToUser') {
34          this.set('data.page', 'user');
35        }
36      },
37      userPathChanged: function(path) {
38        // Redirect from /user/ and /user to /user/view
39        if (path === '/' || path === '') {
40          this.set('userRoute.path', '/view');
41        }
42      }
43    })
44  </script>
45</dom-module>
46