html5mode在角度不起作用

时间:2016-03-09 22:11:28

标签: angularjs apache

尝试在this教程之后使用html5mode。我做过的事情 -

  1. app.js

    的配置关闭中

    $locationProvider.html5Mode(true);

  2. index.html的head标记内。在test.com中部署应用

    <base href="/">

  3. 在apache vhost conf中重写配置。

    <Directory D:/wamp/www/test.com> RewriteEngine On
    # If an existing asset or directory is requested go to it as it is RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d RewriteRule ^ - [L] # If the requested resource doesn't exist, use index.html RewriteRule ^ /index.html </Directory>

  4. 完成这些步骤后,我重启了apache 结果:当我访问郊区时 -

    1. test.com/dashboard它正在重定向到test.com

    2. test.com/#/dashboard网址变形为test.com/#%2Fdashboard。当我点击刷新时,它会重定向回test.com

    3. 路由 -

      .config(['$routeProvider','$httpProvider','$locationProvider', 
          function($routeProvider, $httpProvider, $locationProvider) {
          $tu="templates/";
          $routeProvider
          .when("/", { templateUrl:$tu+'home/index.html' })
          .when("/dashboard", {templateUrl:$tu+'dashboard/index.html'})
          .when("/notes", {templateUrl:$tu+'notes/index.html'})
           $httpProvider.defaults.withCredentials = true;
           $locationProvider.html5Mode(true);
          }])
      

      我也浏览过文档和其他教程,但未能使其完全正常工作/理解。请帮忙!!

0 个答案:

没有答案