OLD | NEW |
| (Empty) |
1 'use strict'; | |
2 | |
3 Polymer({ | |
4 is: 'app-location', | |
5 | |
6 properties: { | |
7 /** | |
8 * A model representing the deserialized path through the route tree, as | |
9 * well as the current queryParams. | |
10 */ | |
11 route: { | |
12 type: Object, | |
13 notify: true | |
14 }, | |
15 | |
16 /** | |
17 * In many scenarios, it is convenient to treat the `hash` as a stand-in | |
18 * alternative to the `path`. For example, if deploying an app to a stat
ic | |
19 * web server (e.g., Github Pages) - where one does not have control ove
r | |
20 * server-side routing - it is usually a better experience to use the ha
sh | |
21 * to represent paths through one's app. | |
22 * | |
23 * When this property is set to true, the `hash` will be used in place o
f | |
24 | |
25 * the `path` for generating a `route`. | |
26 */ | |
27 useHashAsPath: { | |
28 type: Boolean, | |
29 value: false | |
30 }, | |
31 | |
32 /** | |
33 * A regexp that defines the set of URLs that should be considered part | |
34 * of this web app. | |
35 * | |
36 * Clicking on a link that matches this regex won't result in a full pag
e | |
37 * navigation, but will instead just update the URL state in place. | |
38 * | |
39 * This regexp is given everything after the origin in an absolute | |
40 * URL. So to match just URLs that start with /search/ do: | |
41 * url-space-regex="^/search/" | |
42 * | |
43 * @type {string|RegExp} | |
44 */ | |
45 urlSpaceRegex: { | |
46 type: String, | |
47 notify: true | |
48 }, | |
49 | |
50 /** | |
51 * A set of key/value pairs that are universally accessible to branches | |
52 * of the route tree. | |
53 */ | |
54 __queryParams: { | |
55 type: Object | |
56 }, | |
57 | |
58 /** | |
59 * The pathname component of the current URL. | |
60 */ | |
61 __path: { | |
62 type: String | |
63 }, | |
64 | |
65 /** | |
66 * The query string portion of the current URL. | |
67 */ | |
68 __query: { | |
69 type: String | |
70 }, | |
71 | |
72 /** | |
73 * The hash portion of the current URL. | |
74 */ | |
75 __hash: { | |
76 type: String | |
77 }, | |
78 | |
79 /** | |
80 * The route path, which will be either the hash or the path, depending | |
81 * on useHashAsPath. | |
82 */ | |
83 path: { | |
84 type: String, | |
85 observer: '__onPathChanged' | |
86 } | |
87 }, | |
88 | |
89 behaviors: [Polymer.AppRouteConverterBehavior], | |
90 | |
91 observers: [ | |
92 '__computeRoutePath(useHashAsPath, __hash, __path)' | |
93 ], | |
94 | |
95 __computeRoutePath: function() { | |
96 this.path = this.useHashAsPath ? this.__hash : this.__path; | |
97 }, | |
98 | |
99 __onPathChanged: function() { | |
100 if (!this._readied) { | |
101 return; | |
102 } | |
103 | |
104 if (this.useHashAsPath) { | |
105 this.__hash = this.path; | |
106 } else { | |
107 this.__path = this.path; | |
108 } | |
109 } | |
110 }); | |
OLD | NEW |