Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2941)

Unified Diff: chrome/browser/resources/settings/route.js

Issue 2231203002: Settings Router Refactor: Normalize URL only for main settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/route.js
diff --git a/chrome/browser/resources/settings/route.js b/chrome/browser/resources/settings/route.js
index e39b6acfb4a974ef04b4a57bebe80bf9bd522430..f1b2231dc62c4b4f5a58614fefdb01ac35c24226 100644
--- a/chrome/browser/resources/settings/route.js
+++ b/chrome/browser/resources/settings/route.js
@@ -263,27 +263,37 @@ cr.define('settings', function() {
};
/**
- * The current active route. This updated only by settings.navigateTo.
+ * The current active route. This updated is only by settings.navigateTo or
+ * settings.initializeRouteFromUrl.
* @private {!settings.Route}
*/
var currentRoute_ = Route.BASIC;
/**
- * The current query parameters. This updated only by settings.navigateTo.
+ * The current query parameters. This is updated only by settings.navigateTo
+ * or settings.initializeRouteFromUrl.
* @private {!URLSearchParams}
*/
var currentQueryParameters_ = new URLSearchParams();
- // Initialize the route and query params from the URL.
- (function() {
+ /** @private */
+ var initializeRouteFromUrlCalled_ = false;
+
+ /**
+ * Initialize the route and query params from the URL.
+ */
+ var initializeRouteFromUrl = function() {
+ assert(!initializeRouteFromUrlCalled_);
+ initializeRouteFromUrlCalled_ = true;
+
var route = getRouteForPath(window.location.pathname);
if (route) {
currentRoute_ = route;
currentQueryParameters_ = new URLSearchParams(window.location.search);
} else {
- window.history.pushState(undefined, '', Route.BASIC.path);
+ window.history.replaceState(undefined, '', Route.BASIC.path);
}
- })();
+ };
/**
* Helper function to set the current route and notify all observers.
@@ -343,6 +353,7 @@ cr.define('settings', function() {
Route: Route,
RouteObserverBehavior: RouteObserverBehavior,
getRouteForPath: getRouteForPath,
+ initializeRouteFromUrl: initializeRouteFromUrl,
getCurrentRoute: getCurrentRoute,
getQueryParameters: getQueryParameters,
navigateTo: navigateTo,
« no previous file with comments | « chrome/browser/resources/settings/compiled_resources2.gyp ('k') | chrome/browser/resources/settings/settings.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698