我使用的是Express,它从静态目录加载AngularJS.通常情况下,我会请求http://localhost/
,其中Express为我提供index.html
和所有正确的Angular文件等.在我的Angular应用程序中,我设置了这些路由,替换ng-view
中的内容:
$routeProvider.when('/', {
templateUrl: '/partials/main.html',
controller: MainCtrl,
});
$routeProvider.when('/project/:projectId', {
templateUrl: '/partials/project.html',
controller: ProjectCtrl,
});
$locationProvider.html5Mode(true);
在我的主页上,我有一个指向<a href="/project/{{project.id}}">
的链接,它将成功加载模板,并将我指向http://localhost/project/3
或我指定的任何ID.问题是,当我try 将浏览器指向http://localhost/project/3
或刷新页面时,请求将发送到Express/Node服务器,后者返回Cannot GET /project/3
.
How do I setup my Express routes to accommodate for this? I'm guessing it will require the use of $location
in Angular (although I'd prefer to avoid the ugly ?searches and #hashes they use), but I'm clueless about how to go about setting up the Express routes to handle this.
谢谢