in polygerrit-ui/app/elements/core/gr-router/gr-router.ts [819:1115]
_startRouter() {
const base = getBaseUrl();
if (base) {
page.base(base);
}
GerritNav.setup(
(url, redirect?) => {
if (redirect) {
page.redirect(url);
} else {
page.show(url);
}
},
params => this._generateUrl(params),
params => this._generateWeblinks(params),
x => x
);
page.exit('*', (_, next) => {
if (!this._isRedirecting) {
this.reporting.beforeLocationChanged();
}
this._isRedirecting = false;
this._isInitialLoad = false;
next();
});
// Remove the tracking param 'usp' (User Source Parameter) from the URL,
// just to have users look at cleaner URLs.
page((ctx, next) => {
if (window.URLSearchParams) {
const pathname = toPathname(ctx.canonicalPath);
const searchParams = toSearchParams(ctx.canonicalPath);
if (searchParams.has('usp')) {
const usp = searchParams.get('usp');
this.reporting.reportLifeCycle(LifeCycle.USER_REFERRED_FROM, {usp});
searchParams.delete('usp');
this._redirect(toPath(pathname, searchParams));
return;
}
}
next();
});
// Middleware
page((ctx, next) => {
document.body.scrollTop = 0;
if (ctx.hash.match(RoutePattern.PLUGIN_SCREEN)) {
// Redirect all urls using hash #/x/plugin/screen to /x/plugin/screen
// This is needed to allow plugins to add basic #/x/ screen links to
// any location.
this._redirect(ctx.hash);
return;
}
// Fire asynchronously so that the URL is changed by the time the event
// is processed.
setTimeout(() => {
const detail: LocationChangeEventDetail = {
hash: window.location.hash,
pathname: window.location.pathname,
};
this.dispatchEvent(
new CustomEvent('location-change', {
detail,
composed: true,
bubbles: true,
})
);
}, 1);
next();
});
this._mapRoute(RoutePattern.ROOT, '_handleRootRoute');
this._mapRoute(RoutePattern.DASHBOARD, '_handleDashboardRoute');
this._mapRoute(
RoutePattern.CUSTOM_DASHBOARD,
'_handleCustomDashboardRoute'
);
this._mapRoute(
RoutePattern.PROJECT_DASHBOARD,
'_handleProjectDashboardRoute'
);
this._mapRoute(
RoutePattern.LEGACY_PROJECT_DASHBOARD,
'_handleLegacyProjectDashboardRoute'
);
this._mapRoute(RoutePattern.GROUP_INFO, '_handleGroupInfoRoute', true);
this._mapRoute(
RoutePattern.GROUP_AUDIT_LOG,
'_handleGroupAuditLogRoute',
true
);
this._mapRoute(
RoutePattern.GROUP_MEMBERS,
'_handleGroupMembersRoute',
true
);
this._mapRoute(
RoutePattern.GROUP_LIST_OFFSET,
'_handleGroupListOffsetRoute',
true
);
this._mapRoute(
RoutePattern.GROUP_LIST_FILTER_OFFSET,
'_handleGroupListFilterOffsetRoute',
true
);
this._mapRoute(
RoutePattern.GROUP_LIST_FILTER,
'_handleGroupListFilterRoute',
true
);
this._mapRoute(
RoutePattern.GROUP_SELF,
'_handleGroupSelfRedirectRoute',
true
);
this._mapRoute(RoutePattern.GROUP, '_handleGroupRoute', true);
this._mapRoute(RoutePattern.PROJECT_OLD, '_handleProjectsOldRoute');
this._mapRoute(
RoutePattern.REPO_COMMANDS,
'_handleRepoCommandsRoute',
true
);
this._mapRoute(RoutePattern.REPO_GENERAL, '_handleRepoGeneralRoute');
this._mapRoute(RoutePattern.REPO_ACCESS, '_handleRepoAccessRoute');
this._mapRoute(RoutePattern.REPO_DASHBOARDS, '_handleRepoDashboardsRoute');
this._mapRoute(
RoutePattern.BRANCH_LIST_OFFSET,
'_handleBranchListOffsetRoute'
);
this._mapRoute(
RoutePattern.BRANCH_LIST_FILTER_OFFSET,
'_handleBranchListFilterOffsetRoute'
);
this._mapRoute(
RoutePattern.BRANCH_LIST_FILTER,
'_handleBranchListFilterRoute'
);
this._mapRoute(RoutePattern.TAG_LIST_OFFSET, '_handleTagListOffsetRoute');
this._mapRoute(
RoutePattern.TAG_LIST_FILTER_OFFSET,
'_handleTagListFilterOffsetRoute'
);
this._mapRoute(RoutePattern.TAG_LIST_FILTER, '_handleTagListFilterRoute');
this._mapRoute(
RoutePattern.LEGACY_CREATE_GROUP,
'_handleCreateGroupRoute',
true
);
this._mapRoute(
RoutePattern.LEGACY_CREATE_PROJECT,
'_handleCreateProjectRoute',
true
);
this._mapRoute(RoutePattern.REPO_LIST_OFFSET, '_handleRepoListOffsetRoute');
this._mapRoute(
RoutePattern.REPO_LIST_FILTER_OFFSET,
'_handleRepoListFilterOffsetRoute'
);
this._mapRoute(RoutePattern.REPO_LIST_FILTER, '_handleRepoListFilterRoute');
this._mapRoute(RoutePattern.REPO, '_handleRepoRoute');
this._mapRoute(RoutePattern.PLUGINS, '_handlePassThroughRoute');
this._mapRoute(
RoutePattern.PLUGIN_LIST_OFFSET,
'_handlePluginListOffsetRoute',
true
);
this._mapRoute(
RoutePattern.PLUGIN_LIST_FILTER_OFFSET,
'_handlePluginListFilterOffsetRoute',
true
);
this._mapRoute(
RoutePattern.PLUGIN_LIST_FILTER,
'_handlePluginListFilterRoute',
true
);
this._mapRoute(RoutePattern.PLUGIN_LIST, '_handlePluginListRoute', true);
this._mapRoute(
RoutePattern.QUERY_LEGACY_SUFFIX,
'_handleQueryLegacySuffixRoute'
);
this._mapRoute(RoutePattern.QUERY, '_handleQueryRoute');
this._mapRoute(RoutePattern.CHANGE_ID_QUERY, '_handleChangeIdQueryRoute');
this._mapRoute(RoutePattern.DIFF_LEGACY_LINENUM, '_handleLegacyLinenum');
this._mapRoute(
RoutePattern.CHANGE_NUMBER_LEGACY,
'_handleChangeNumberLegacyRoute'
);
this._mapRoute(RoutePattern.DIFF_EDIT, '_handleDiffEditRoute', true);
this._mapRoute(RoutePattern.CHANGE_EDIT, '_handleChangeEditRoute', true);
this._mapRoute(RoutePattern.COMMENT, '_handleCommentRoute');
this._mapRoute(RoutePattern.COMMENTS_TAB, '_handleCommentsRoute');
this._mapRoute(RoutePattern.DIFF, '_handleDiffRoute');
this._mapRoute(RoutePattern.CHANGE, '_handleChangeRoute');
this._mapRoute(RoutePattern.CHANGE_LEGACY, '_handleChangeLegacyRoute');
this._mapRoute(RoutePattern.AGREEMENTS, '_handleAgreementsRoute', true);
this._mapRoute(
RoutePattern.NEW_AGREEMENTS,
'_handleNewAgreementsRoute',
true
);
this._mapRoute(
RoutePattern.SETTINGS_LEGACY,
'_handleSettingsLegacyRoute',
true
);
this._mapRoute(RoutePattern.SETTINGS, '_handleSettingsRoute', true);
this._mapRoute(RoutePattern.REGISTER, '_handleRegisterRoute');
this._mapRoute(RoutePattern.LOG_IN_OR_OUT, '_handlePassThroughRoute');
this._mapRoute(
RoutePattern.IMPROPERLY_ENCODED_PLUS,
'_handleImproperlyEncodedPlusRoute'
);
this._mapRoute(RoutePattern.PLUGIN_SCREEN, '_handlePluginScreen');
this._mapRoute(
RoutePattern.DOCUMENTATION_SEARCH_FILTER,
'_handleDocumentationSearchRoute'
);
// redirects /Documentation/q/* to /Documentation/q/filter:*
this._mapRoute(
RoutePattern.DOCUMENTATION_SEARCH,
'_handleDocumentationSearchRedirectRoute'
);
// Makes sure /Documentation/* links work (doin't return 404)
this._mapRoute(
RoutePattern.DOCUMENTATION,
'_handleDocumentationRedirectRoute'
);
// Note: this route should appear last so it only catches URLs unmatched
// by other patterns.
this._mapRoute(RoutePattern.DEFAULT, '_handleDefaultRoute');
page.start();
}