Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 02a4582

Browse files
sebholsteinpetebacondarwin
authored andcommitted
docs(docs): preserve path to current doc page when switching versions
Preserve URL path when switching between doc versions. Closes #4661 Closes #5773
1 parent e324c14 commit 02a4582

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

docs/src/templates/js/docs.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ var docsApp = {
55
filter: {}
66
};
77

8-
docsApp.controller.DocsVersionsCtrl = ['$scope', '$window', 'NG_VERSIONS', 'NG_VERSION', function($scope, $window, NG_VERSIONS, NG_VERSION) {
8+
docsApp.controller.DocsVersionsCtrl = ['$scope', '$rootScope', '$window', 'NG_VERSIONS', 'NG_VERSION', function($scope, $rootScope, $window, NG_VERSIONS, NG_VERSION) {
99
$scope.docs_versions = NG_VERSIONS;
1010
$scope.docs_version = NG_VERSIONS[0];
11+
1112
$scope.jumpToDocsVersion = function(version) {
12-
$window.location = version.url;
13+
var currentPagePath = '';
14+
15+
// preserve URL path when switching between doc versions
16+
if (angular.isObject($rootScope.currentPage) && $rootScope.currentPage.section && $rootScope.currentPage.id) {
17+
currentPagePath = '/' + $rootScope.currentPage.section + '/' + $rootScope.currentPage.id;
18+
}
19+
20+
$window.location = version.url + currentPagePath;
1321
};
1422
}];
1523

@@ -645,7 +653,7 @@ docsApp.serviceFactory.sections = ['NG_PAGES', function sections(NG_PAGES) {
645653
}];
646654

647655

648-
docsApp.controller.DocsController = function($scope, $location, $window, $cookies, sections) {
656+
docsApp.controller.DocsController = function($scope, $rootScope, $location, $window, $cookies, sections) {
649657
$scope.fold = function(url) {
650658
if(url) {
651659
$scope.docs_fold = '/notes/' + url;
@@ -736,9 +744,9 @@ docsApp.controller.DocsController = function($scope, $location, $window, $cookie
736744
sectionName = SECTION_NAME[sectionId] || sectionId,
737745
page = sections.getPage(sectionId, partialId);
738746

739-
$scope.currentPage = sections.getPage(sectionId, partialId);
747+
$rootScope.currentPage = sections.getPage(sectionId, partialId);
740748

741-
if (!$scope.currentPage) {
749+
if (!$rootScope.currentPage) {
742750
$scope.partialTitle = 'Error: Page Not Found!';
743751
}
744752

0 commit comments

Comments
 (0)