繁体   English   中英

当我直接使用参数访问url时,AngularJS html5mode = true错误

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

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

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

app.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'});

我也在index.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看起来像是在使用hashbang。 这只是错字吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM