服務器代碼:
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轉換爲普通/
網址。
之後,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);
到角。
感謝您的回答。我只是爲ourdomain.com路由,它使用ng-view鏈接到partials/partial。路由工作得很好,直到我添加'$ locationProvider.html5Mode(true);'在角度。之後,路由停止工作。如果有助於澄清問題,則添加angularjs代碼 –