Skip to content

Commit 8b0c5aa

Browse files
author
Claudio Mezzasalma
committed
Initial support for uiSref in pfVerticalNavigation
1 parent 40f89b3 commit 8b0c5aa

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ node_modules
2727
npm-debug.log
2828
lib
2929
.bower
30+
31+
.vscode

src/navigation/vertical-navigation-directive.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@
565565
</file>
566566
</example>
567567
*/
568-
angular.module('patternfly.navigation').directive('pfVerticalNavigation', ['$location', '$rootScope', '$window', '$document', '$timeout',
569-
function (location, rootScope, $window, $document, $timeout) {
568+
angular.module('patternfly.navigation').directive('pfVerticalNavigation', ['$location', '$rootScope', '$window', '$document', '$timeout', '$state',
569+
function (location, rootScope, $window, $document, $timeout, $state) {
570570
'use strict';
571571
return {
572572
restrict: 'A',
@@ -826,12 +826,23 @@
826826
var navTo;
827827
if (navItem) {
828828
$scope.showMobileNav = false;
829-
navTo = navItem.href;
830-
if (navTo) {
831-
if (navTo.startsWith('#/')) {
832-
navTo = navTo.substring(2);
829+
if (navItem.uiSref && navItem.href) {
830+
throw new Error('Using both uiSref and href on an item is not supported.');
831+
}
832+
if (navItem.uiSref) {
833+
if ($state === undefined) {
834+
throw new Error('uiSref is defined on item, but no $state has been injected. ' +
835+
'Did you declare a dependency on "ui.router" module in your app?');
836+
}
837+
$state.go(navItem.uiSref, navItem.uiSrefOptions);
838+
} else {
839+
navTo = navItem.href;
840+
if (navTo) {
841+
if (navTo.startsWith('#/')) {
842+
navTo = navTo.substring(2);
843+
}
844+
location.path(navTo);
833845
}
834-
location.path(navTo);
835846
}
836847
if ($scope.navigateCallback) {
837848
$scope.navigateCallback(navItem);

0 commit comments

Comments
 (0)