angular项目SEO去掉路由#详解

来源:互联网 发布:传智播客oa项目数据库 编辑:程序博客网 时间:2024/06/06 03:23

angular项目路由不使用#管理

1、在路由配置下添加 $locationProvider.html5Mode(true);

.config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
}])
2、需要本地查看到效果需要配置<base href="xxx/xxx">,href路径为项目根目录的文件夹。比如我的项目index.html的路径是tmw/app/index.html,那么tmw/app就是根目录路径。

(在配置nginx后在index.html中<base href="xxx/xxx">改为<base href="/">href路径为项目根目录的文件夹)

3、配置本地nginx环境

下载安装后(http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html)

对其中nginx.conf文件进行修改(仅需修改蓝色文字部分)

server {
        listen       8890;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
root D:xxx/xxx/xxx/xxx;                  此处为项目中index.html位置
index index.html index.htm;
try_files $uri $uri/ /index.html =404;   
}