从 Angular 项目中的 Url 中删除 #。
http://localhost/#/about ---> http://localhost/about
1) 在 index.html 中添加基本 url
2) 在您的 app.js 或 routes.js 中使用 html5 历史记录
if(window.history && window.history.pushState){
$locationProvider.html5Mode(true);
}
3)服务器端配置——Grunt Server: middleware: function (connect) { var middlewares = []; middlewares.push(modRewrite([ '!/assets|\.html|\.js|\.css|\woff|\ttf|\swf$ /index.html' ]));
middlewares.push(connect.static('.tmp'));
middlewares.push(connect().use(
'/bower_components',
connect.static('./bower_components')
));
middlewares.push(connect.static(appConfig.app));
//middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
return middlewares;
}
-Ngnix Server
location ~ ^/(scripts.*js|styles|images) {
gzip_static on;
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
#location /api1 {
# rewrite ^/api1/(.*) /$1 break;
# proxy_redirect off;
# proxy_pass https://api1.example.com;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto https;
# proxy_set_header Authorization $http_authorization;
#}
#location /api2 {
# rewrite ^/api2/(.*) /$1 break;
# proxy_redirect off;
# proxy_pass https://api2.example.com;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto https;
# proxy_set_header Authorization $http_authorization;
#}
location / {
try_files $uri /index.html;
}