[英]Angular UI Router controllers instantiated multiple times - Direct route
我已经设置了父/子路由,当我使用state.go()在代码中更改状态时,一切工作都很好。 当我尝试仅使用URL直接进入子路线时,就会出现问题。 当我这样做时,控制器将被初始化多次。
这是我的app.js
$stateProvider
.state('home', {
url: "/",
templateUrl: "Views/home.html",
controller: 'HomeController',
controllerAs: 'vm'
})
.state('ticketsMaster', {
abstract: true,
templateUrl: "Views/tickets-master.html",
url: "^/performances?featureCode&theatreId",
controller: 'TicketsMasterController',
controllerAs: 'vm'
})
.state('ticketsMaster.performances', {
url: "^/performances?featureCode&theatreId",
templateUrl: "Views/performances.html",
controller: 'PerformancesController',
controllerAs: 'vm'
})
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
home.html是我的用户界面视图的主页
我的tickets-master.html上还有另一个ui视图,该视图加载了我的孩子视图(表演)。
当直接转到/performances?featureCode=1111&theatreId=1
它将加载我的TicketsMasterController
和Performances控制器2或3次。
任何帮助,将不胜感激。
我在这里找到了答案:
https://github.com/angular-ui/ui-router/issues/372
将此行添加到app.config中:
$locationProvider.html5Mode(true).hashPrefix('!')
并将此行包含在index.html的开头:
<base href="/">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.