我正在尝试设置角度路由。当我使用<a ui-sref="classification.sequences.index">
导航到路线时,它会被路由到正确的位置,将网址更改为http://localhost/classification/sequences/index
并输出输入0,输入5,在控制台中输入2.
但是,如果我手动刷新页面或从头开始导航到此URL,则不会发生任何路由,也不会向控制台输出任何内容。但是,如果我点击链接按钮,它将正确路由。
是否有必须设置的东西,以便角度试图在负载上路由或者我在某处犯了一个愚蠢的错误?
我的代码可以在下面看到 -
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");
}
})
;
}
]);
答案 0 :(得分:0)
事实证明我在配置行之后没有调用policyManagerApp.run()
所以它从来没有针对起始网址进行评估。