0
我想設置角路由。當我使用<a ui-sref="classification.sequences.index">
導航到路線時,它將被路由到正確的位置,將url更改爲http://localhost/classification/sequences/index
,輸出將輸入0,輸入5,在控制檯中輸入2。如何獲取Angular UI路由器在頁面加載路由
但是,如果我手動刷新頁面或從頭開始導航到此網址,則不會發生路由,也不會向控制檯輸出任何內容。但是,如果我點擊鏈接按鈕,它會正確路由。
有什麼你必須設置這樣的角度會試圖負載路線或我犯了一個愚蠢的錯誤?
我的代碼可以如下─
policyManagerApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function($stateProvider, $urlRouterProvider, $locationProvider) {
// Activates HTML5 History API for modern browsers and sets the hashbang
// for legacy browsers
$locationProvider.html5Mode(true).hashPrefix('!');
$urlRouterProvider.when("", "/classification/index");
$urlRouterProvider.when("/", "/classification/index");
// For any unmatched url, send to /classification/index
$urlRouterProvider.otherwise("/classification/index");
$stateProvider
.state('classification', {
url: '/classification',
abstract: true,
template: '<ui-view/>',
onEnter: function() {
console.log("enter 0");
}
})
.state('classification.index', {
url: '/index',
templateUrl: '/html/partials/classification/index.html',
controller: 'PolicyManagerCtrl',
data: {
ncyBreadcrumbLabel: 'Classification'
},
onEnter: function() {
console.log("enter 1");
}
})
.state('classification.sequences', {
url: '/sequences',
abstract: true,
template: '<ui-view/>',
onEnter: function() {
console.log("enter 5");
}
})
.state('classification.sequences.index', {
url: '/index',
templateUrl: '/html/partials/classification/sequences/index.html',
data: {
ncyBreadcrumbLabel: 'Collection Sequences'
},
onEnter: function() {
console.log("enter 2");
}
})
.state('classification.sequences.detail', {
url: '/:id',
templateUrl: '/html/partials/classification/sequences/detail.html',
controller: 'SequenceDetailCtrl',
data: {
ncyBreadcrumbParent: 'classification.sequences.index',
ncyBreadcrumbLabel: '{{sequence.name}}'
},
onEnter: function() {
console.log("enter 3");
}
})
;
}
]);