| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('settings', function() { | 5 cr.define('settings', function() { |
| 6 /** | 6 /** |
| 7 * Class for navigable routes. May only be instantiated within this file. | 7 * Class for navigable routes. May only be instantiated within this file. |
| 8 * @constructor | 8 * @constructor |
| 9 * @param {string} path | 9 * @param {string} path |
| 10 * @private | 10 * @private |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return; | 351 return; |
| 352 } | 352 } |
| 353 | 353 |
| 354 var url = route.path; | 354 var url = route.path; |
| 355 if (opt_dynamicParameters) { | 355 if (opt_dynamicParameters) { |
| 356 var queryString = opt_dynamicParameters.toString(); | 356 var queryString = opt_dynamicParameters.toString(); |
| 357 if (queryString) | 357 if (queryString) |
| 358 url += '?' + queryString; | 358 url += '?' + queryString; |
| 359 } | 359 } |
| 360 | 360 |
| 361 // History serializes the state, so we don't push the actual route object. |
| 362 var previousRoutePath = currentRoute_.path; |
| 361 setCurrentRoute(route, params); | 363 setCurrentRoute(route, params); |
| 362 window.history.pushState(undefined, '', url); | 364 window.history.pushState(previousRoutePath, '', url); |
| 363 }; | 365 }; |
| 364 | 366 |
| 365 window.addEventListener('popstate', function(event) { | 367 window.addEventListener('popstate', function(event) { |
| 366 // On pop state, do not push the state onto the window.history again. | 368 // On pop state, do not push the state onto the window.history again. |
| 367 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, | 369 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, |
| 368 new URLSearchParams(window.location.search)); | 370 new URLSearchParams(window.location.search)); |
| 369 }); | 371 }); |
| 370 | 372 |
| 371 return { | 373 return { |
| 372 Route: Route, | 374 Route: Route, |
| 373 RouteObserverBehavior: RouteObserverBehavior, | 375 RouteObserverBehavior: RouteObserverBehavior, |
| 374 getRouteForPath: getRouteForPath, | 376 getRouteForPath: getRouteForPath, |
| 375 getCurrentRoute: getCurrentRoute, | 377 getCurrentRoute: getCurrentRoute, |
| 376 getQueryParameters: getQueryParameters, | 378 getQueryParameters: getQueryParameters, |
| 377 navigateTo: navigateTo, | 379 navigateTo: navigateTo, |
| 378 }; | 380 }; |
| 379 }); | 381 }); |
| OLD | NEW |