Skip to content

Commit

Permalink
Исправил ошибку открытия определенной станицы по внешней ссылке.
Browse files Browse the repository at this point in the history
  • Loading branch information
knikitin committed May 20, 2016
1 parent fa12a00 commit 7a7745e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions angular/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ app.run(
]
);

app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function($stateProvider, $urlRouterProvider, $locationProvider) {

$urlRouterProvider.otherwise('/');

$locationProvider.hashPrefix("!");

$stateProvider
.state('mainState', {
.state("home", { url: "", template: ''}) // начальное состояние. попали в него, значит перешли без цели

.state("mainState", {
url: "/{url}",
templateUrl: "content.html",
controller: ['$scope', '$http', '$sce', '$stateParams', function($scope, $http, $sce, $stateParams){
Expand All @@ -27,7 +31,7 @@ app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
$scope.fullContent = {};
$scope.sce = $sce;
$scope.showContent = true;

if ($stateParams.url === "/") {
$scope.fullContent = {};
document.location.href='/';
Expand All @@ -47,6 +51,7 @@ app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',

}]
})

}]);


Expand All @@ -57,7 +62,10 @@ app.controller('mainMenu', [ '$http', '$state', function($http, $state) {
mainMenu.listMenu = [];
$http.get("/menu.json").success(function(data){
mainMenu.listMenu = data;
$state.go('mainState', {"url":mainMenu.listMenu[1].url});
if ($state.$current.name == "home") {
$state.go('mainState', {"url":mainMenu.listMenu[1].url});
}

});

}]);
Expand Down

0 comments on commit 7a7745e

Please sign in to comment.