【发布时间】:2013-10-11 03:52:28
【问题描述】:
服务器代码:
app.get('/', function(req, res){
console.log('executed "/"')
res.render('home');
});
app.get('/partials/:name', function (req, res) {
console.log('executed partials:name');
var name = req.params.name;
console.log(name);
res.render('partials/' + name);
});
在我将$locationProvider.html5Mode(true); 将'/#/' url 转换为常规/ url 之前,该代码运行良好。
之后,console.log('executed partials:name'); 无法执行。 Documentation 说:-
Server side
Using this mode requires URL rewriting on server side, basically you have to rewrite all
your links to entry point of your application (e.g. index.html)
我尝试的更改不起作用。有哪些改变?
编辑:以下是角码:
var myApp = angular.module('myApp', []);
myApp.config(['$routeProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/partial',
controller: 'homePage'
}).
otherwise({redirectTo: '/login'});
$locationProvider.html5Mode(true);
}]);
我再次提到,路由工作得很好,直到我将 $locationProvider.html5Mode(true); 添加到 angular。
【问题讨论】:
标签: node.js angularjs express angularjs-routing