将我的应用页面直接加载到链接/ pl / param1时,所有文件都无法加载,因为angular会在目录前面添加。我该如何解决?
angular.module('html5app', [
'ngRoute'
])
.config(['$locationProvider', '$routeProvider', function config ($locationProvider, $routeProvider){
//enabling HTML5 mode
$locationProvider.html5Mode(true).hashPrefix('!');
//setting up routes
$routeProvider.when('/',{ templateUrl: '/partials/home.html', controller: 'HomeCtrl as home'});
$routeProvider.when('/about',{ templateUrl: '/partials/about.html'});
$routeProvider.when('/pl',{ templateUrl: '/partials/plPartials/pl.html'});
$routeProvider.when('/pl/:name',{ templateUrl: '/partials/plPartials/pl.html', controller: 'PlCtrl as plDetail'});
}]);
无法加载网址(为什么pl会在端口号后卡住?):
http://localhost:3000/pl/js/app.js
附加SEO服务器:
var express = require('express'),
app = express();
//initialize static server that will spit out contents of public folder
app.use('/', function(){
var staticPath = __dirname + '/',
req = arguments[0];
if(/_escaped_fragment_=/.test(req.url)){ // testing if url contains '_escaped_fragment_=' part
req.url = req.url.replace(/\?.*$/,'').replace(/\/+$/,''); // if it does, then strip it
// if url became empty then it means 'http://someurl/?_escaped_fragment_=' was requested,
// so we need to return pre-rendered index.html, otherwise we should add '.html' extension
// so that it would return 'posts.html' when http://someurl/posts?_escaped_fragment_= is requested
req.url += (req.url === '') ? '/index.html' : '.html';
staticPath += 'snapshots'; // making '/snapshots' the base directory of our static server
} else {
staticPath += 'public'; // if it's a regular link, then initialize static server in '/public' directory
}
express.static(staticPath).apply(this, arguments);
});
//send our main angular html file if any link without dot is requested, e.g. 'http://someurl/about'
//this is our actual server side redirect, we don't send index.html when there's dot in link assuming such a request
//is for static data like .js, .css or .html
app.get('/[^\.]+$', function(req, res){
res.set('Content-Type', 'text/html')
.sendfile(__dirname + '/public/index.html');
});
app.listen(3000); //the express server will start on port 9823
console.log('\nangular SEO server started on port 3000');