我遇到了一些(虽然不是很严重的)$routeProvider
的问题。
http://localhost/thisapp/运行正常,并且完美地重定向到.otherwise()
。但是一旦应用程序加载并落在“主页”网址上(http://localhost/thisapp/#/)
那么它就会出错。
如果我导航到http://localhost/thisapp,$location
解析为http://localhost/thisapp/#/
如果我刷新(因为你知道用户会这样做),那么代码就会出错
我尝试使用$locationProvider
,但那更加令人困惑。似乎我读得越多,就越困惑,因为文档中记录的内容似乎不起作用。(如果我取消下面的$locationProvider
行的注释,则不会生成任何内容)。我查看了各种教程和StackOverflow上的问题,但似乎不像应该工作那样。
以下是我的配置代码:
myApp.config(function($routeProvider, $locationProvider) {
// commented cuz it's not working
// $locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: 'app2/components/templates/overview.html',
controller: 'overviewController'
})
.when('/all_overview', {
templateUrl: 'app2/components/templates/overview.html',
controller: 'overviewController'
})
.when('/all_procurement', {
templateUrl: 'app2/components/templates/procurement.html',
controller: 'procurementController'
})
.when('/all_social', {
templateUrl: 'app2/components/templates/social.html',
controller: 'socialController'
})
.when('/all_strengthening', {
templateUrl: 'app2/components/templates/strengthening.html',
controller: 'strengtheningController'
})
.when('/all_sales', {
templateUrl: 'app2/components/templates/sales.html',
controller: 'salesController'
})
// otherwise go to all_overview
.otherwise({
redirectTo: '/all_overview'
});
});