代码之家  ›  专栏  ›  技术社区  ›  Tanwir Alam

使用Codeigniter网站URL从angularjs中删除#后,如果重新加载,则找不到其give 404页面。。。(页面未重新加载的主要错误)?[副本]

  •  1
  • Tanwir Alam  · 技术社区  · 6 年前

    使用Codeigniter网站URL从angularjs中删除#后,html无法在主ng视图中正确加载。(页面未重新加载的主要错误) 我应该做些什么来克服这个问题。

    var app = angular.module('main-App', ['ngRoute','angularUtils.directives.dirPagination']);
    app.config(['$routeProvider','$locationProvider',
    function ($routeProvider,$locationProvider) { 
        $routeProvider.
                when('/', {
                    templateUrl: 'templates/home.html',
                    controller: 'AdminController'
                }).
                when('/items', {
                    templateUrl: 'templates/items.html',
                    controller: 'ItemController'
                }).
                when('/users', {
                    templateUrl: 'templates/user_view.html',
                    controller: 'ItemController'
                }).
                when('/wearhouse',{
                    templateUrl:'templates/wearhouse_view.html',
                    controller:'ItemController'
                }).
                when('/units',{
                    templateUrl:'templates/units_view.html',
                    controller:'ItemController'
                }).
                 when('/product',{
                    templateUrl:'templates/product_view.html',
                    controller:'ItemController'
                }).
                 when('/productListing',{
                    templateUrl:'templates/product_listing_view.html',
                    controller:'ItemController'
                }).
                when('/stock',{
                    templateUrl:'templates/stoke_view.html',
                    controller:'ItemController' 
                }).
                otherwise(
                {redirectTo : '/'}
                );
    
                 $locationProvider.html5Mode(true);
      }]);
    

    codeigniter中的.htaccess文件:-

     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ index.php/$1 [L]
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Shashank Vivek    6 年前

    这是因为当你删除 hash 从您的url,您的服务器尝试 map 整个 url 然后将数据提供给客户端。

    当你有 # 在url中,服务器会忽略后面的内容 # 并简单地映射之前存在的路径 #

    适用于: www.something.com\resoucePath\#abc\def

    服务器只是忽略 abc\def 这就是 angularJS 利用路由漏洞。

    其中: www.something.com\resoucePath\abc\def

    服务器继续查找 url地址 映射或 @path 匹配 \abc 然后 \def

    您需要配置服务器来处理此类请求。我也有过同样的问题, this link will surely help you get some idea