欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ace admin ajax加载页面,循环加载首页的解决办法

程序员文章站 2022-06-16 09:40:16
...

ace admin 1.4

 

出现循环加载,主要是因为找不到页面,

  

需要ajax加载的div

<div class="page-content-area" data-ajax-content="true">
	<!-- ajax content goes here -->
</div>

 

修改ace-1.4.0\assets\js\src\ace.basics.js

var demo_ajax_options = {
	 'close_active': true,
	 
	 close_mobile_menu: '#sidebar',
	 close_dropdowns: true,
	 
	 'default_url': 'page/index',//default hash
	 'content_url': function(hash) {
		//***NOTE***
		//this is for Ace demo only, you should change it to return a valid URL
		//please refer to documentation for more info

		if( !hash.match(/^page\//) ) return false;
		var path = document.location.pathname;

		//for example in Ace HTML demo version we convert /ajax/index.html#page/gallery to > /ajax/content/gallery.html and load it
		if(path.match(/(\/ajax\/)(index\.html)?/))
			return path.replace(/(\/ajax\/)(index\.html)?/, '/ajax/content/'+hash.replace(/^page\//, '')+'.html') ;

		//for example in Ace PHP demo version we convert "ajax.php#page/dashboard" to "ajax.php?page=dashboard" and load it
		return path + "?" + hash.replace(/\//, "=");
	  }			  
}

 修改为自己的逻辑

'default_url': '/welcome',

return contextPath + hash; (contextPath是预置的)

		var demo_ajax_options = {
			 'close_active': true,
			 
			 close_mobile_menu: '#sidebar',
			 close_dropdowns: true,
			 
//			 'default_url': 'page/index',//default hash
			 'default_url': '/welcome',//default hash
			 'content_url': function(hash) {
//				//***NOTE***
//				//this is for Ace demo only, you should change it to return a valid URL
//				//please refer to documentation for more info
//
//				if( !hash.match(/^page\//) ) return false;
//				var path = document.location.pathname;
//
//				//for example in Ace HTML demo version we convert /ajax/index.html#page/gallery to > /ajax/content/gallery.html and load it
//				if(path.match(/(\/ajax\/)(index\.html)?/))
//					return path.replace(/(\/ajax\/)(index\.html)?/, '/ajax/content/'+hash.replace(/^page\//, '')+'.html') ;
//
//				//for example in Ace PHP demo version we convert "ajax.php#page/dashboard" to "ajax.php?page=dashboard" and load it
//				return path + "?" + hash.replace(/\//, "=");
				 if(hash==""){
					 if(window.Pace && Pace.running) Pace.stop();
					 $(this).ace_ajax('stopLoading', true);
				 }
				 return contextPath + hash;
			  }			  
		}

 

菜单栏说明

<a data-url="/welcome" href="#/welcome">
	<i class="menu-icon fa fa-tachometer"></i>
	<span class="menu-text"> Dashboard </span>
</a>

href是链接

data-url 当前页面地址与之对应时高亮选中

 

参考:

Ace Admin 使用教程

https://www.cnblogs.com/LeeScofiled/p/6733625.html