AngularJS html5mode = 当我使用参数直接访问 url 时出现真正的错误


AngularJS html5mode = true error when I access directly url with params

我有一个用Angularjs和Symfony 2开发的应用程序,我启用了html5模式来获取友好的URL。

该应用程序与Symfony 2.3集成以响应服务。

应用.js

 .config(['$routeProvider', '$locationProvider','$provide' , function($routeProvider, $locationProvider,$provide) {
      $provide.decorator('$sniffer', function($delegate) {
            $delegate.history = false;
            return $delegate;
        });
    $routeProvider.when('/home', {templateUrl: 'views/home.html', controller: 'HomeController'});
    $routeProvider.when('/quienes_somos', {templateUrl: 'views/quienes_somos.html', controller: 'QuienesSomosController'});
    $routeProvider.when('/ubicanos', {templateUrl: 'views/ubicanos.html', controller: 'UbicanosController'});
    $routeProvider.when('/ubicanos/:route', {templateUrl: 'views/ubicanos.html', controller: 'UbicanosController'});
    $routeProvider.when('/catalogo', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
    $routeProvider.when('/catalogo/:category', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
    $routeProvider.when('/catalogo/:category/:productid', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});
    $routeProvider.when('/catalogo/results',{templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});
    $routeProvider.when('/noticias', {templateUrl: 'views/noticias.html', controller: 'NoticiasController'});
    $routeProvider.otherwise({redirectTo: '/home'});
        $locationProvider.html5Mode(true);
  }]);

当我尝试直接访问放置类别的路由和参数时,就会出现问题。

http://plastimex.localhost/catalogo/tablilla-plastica

Angularjs 不加载。但是其他路线工作正常。

不工作路线

 $routeProvider.when('/catalogo/:category', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
 $routeProvider.when('/catalogo/:category/:productid', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});

我也在索引上设置了这个.html <base href="/index.html" />

这是 .htaccess

DirectoryIndex app.php
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::'2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app'.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

我已经对htaccess进行了修改以使其正常工作,但并不幸运。它回滚了。

知道吗?请。谢谢。

您已将 html5mode 设置为 true,但您提到的示例 URL 看起来像您正在使用哈希爆炸。这只是一个错别字吗?

http://plastimex.localhost/index.html#/catalogo/tablilla-plastica

应该是

http://plastimex.localhost/catalogo/tablilla-plastica

抱歉,我会将其作为评论,但我没有要点。

相关文档链接:http://docs.angularjs.org/guide/dev_guide.services.$location#hashbang-and-html5-modes