我正在为Codeigniter项目中的重定向实现AngularJS,但它会导致无限重定向。我的目录和文件结构如下:
application controllers admin home.php view admin home index.php listing index.php theme header.php footer.php index.php system
AngularJS代码:
的header.php
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
var sampleApp = angular.module('sampleApp', []);
sampleApp.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.
when('/angular/ci/admin/home/', {
templateUrl: 'home'
}).
when('/angular/ci/admin/home/listing/', {
templateUrl: 'home/listing'
}).
otherwise({
redirectTo: '/angular/ci/admin/home/'
});
}
]);
</script>
<div>header</div>
<div>
<a href="http://localhost/angular/ci/admin/home/">Home</a>
<a href="http://localhost/angular/ci/admin/home/listing/">Listing</a>
</div>
主题/ index.php的
<div ng-app="sampleApp">
<?php
$this->load->view(ADMIN_THEME."header.php");
?>
<div class='ng-view'>
<?php
$this->load->view('admin/'.$pagename);
?>
</div>
<?php
$this->load->view(ADMIN_THEME."footer.php");
?>
</div>
控制器/ home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function index(){
$data['pagename']='home/index';
$this->load->view(ADMIN_THEME.'index',$data);
}
public function listing(){
//echo 'hi';
$this->load->view('admin/listing');
}
}
答案 0 :(得分:0)
您需要重定向到已定义的路径。
换句话说,当你重定向到'/'时,它会通过路径并查找匹配项,因为找不到,所以它会重定向到'/'等。你应该重定向到/ angular / ci / admin / home /或/ angular / ci / admin / home / listing /
祝你好运。