在使用Codeigniter网站URL删除#from angularjs后,如果重新加载则找不到404页面...(页面未重新加载的主要错误)?

时间:2018-04-19 05:07:42

标签: angularjs codeigniter-3

使用Codeigniter网站URL从angularjs中删除#后,在主ng-view中未正确加载html。(页面未重新加载的主要错误) 我该怎么做才能克服这个问题。

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 个答案:

答案 0 :(得分:0)

它正在发生,因为当您从网址中删除hash时,您的服务器会尝试map整个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