我想我明白了!诀窍是将模板设置为简单模式,然后修改范围以包含模板的动态路径。
所以,现在我可以放置一个文件在/foo/bar/baz.html
并查看模板呈现通过去server.com/foo/bar/baz
。
// Routes
app.config(function($routeProvider) {
$routeProvider
// Home
.when('/', {
templateUrl: 'home.html',
controller: 'HomeController'
})
// Catch All
.when('/:templatePath*', {
template: '<ng-include src="templatePath"></ng-include>',
controller: 'CatchAllCtrl'
})
});
// Catch All Controller
app.controller("CatchAllCtrl", function($scope, $routeParams) {
$scope.templatePath = $routeParams.templatePath + '.html';
});
像*? (fi – Ven
对不起?您能解释一下吗? – wesbos
我从来没有搞错Angular的路由,但是我已经读过了Angular UI项目的路由器:https://github.com/angular-ui/ui-router是否满足您的需求? –