【发布时间】:2015-01-17 16:28:03
【问题描述】:
我有一个 Angular 应用程序,因此路由可能如下所示:
angular.module('app').config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'views/home.html',
controller: 'homeController'
})
.when('/foo', {
templateUrl : 'views/foo.html',
controller: 'fooController'
})
.otherwise({
redirectTo : '/'
});
$locationProvider.html5Mode(true);
});
现在,这可能是一个过于简单的问题,但是如果不使用 .when 路由指定它,我可以提供一个永远不会改变并且不需要我添加 javascript 的静态页面吗?例如,假设我想像这样提供 Google 的网站管理员工具验证:
/googlee23dc3443279f430.html
我真的需要创建一个 .when('/googlee23dc3443279f430.html') 路由吗?
编辑:我们还进行了服务器重写,以使非“/”路由仍然提供 index.html 文件,如本 wiki 中所指定(并让 html5mode(true) 在页面刷新时工作):
每次我们想要添加静态页面时不必添加重写条件会很好
【问题讨论】:
-
为什么需要路由?如果静态 html 页面存在于磁盘上,只需将浏览器指向该静态页面的 URL。 Angular 与它无关
-
@link64 好吧,我们正在使用 $locationProvider.html5Mode(true) 并且为了使其与页面刷新一起使用,我们进行了服务器重写以在路由不是时提供应用程序' /',在此 wiki 中指定:github.com/angular-ui/ui-router/wiki/…