刷新页面后如何防止重新加载整个 ng-admin
How to prevent reloading of whole ng-admin after refresh page
我一直卡在刷新页面的问题上。示例:基本应用程序打开并且 url 是 localhost:8000/dashboard
,然后我从菜单或其他任何地方转到用户选项卡并且 url 是 localhost:8000/users/list
。如果我在用户上刷新页面,那么它会再次进入仪表板重新加载整个页面。
后端正在正确处理它,当我创建一个自定义状态并且不指定 'ng-admin' 作为父级时,它停留在它只是进行刷新的位置,但是当我将父级添加到状态时,它会再次重新加载整个应用程序。
还启用了 html5mode。
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
实体添加为 ng-admin 文档指定:
app.config(['NgAdminConfigurationProvider', 'RestangularProvider', function(nga, RestangularProvider) {
var admin = nga.application('Admin') // application main title
.debug(false) // debug disabled
.baseApiUrl('/api/'); // main API endpoint
var users = nga.entity('users');
admin
.addEntity(users);
users.listView()
.title('Admin users')
.fields([
nga.field('name')
.label('Name')
.isDetailLink(true),
nga.field('email')
.label('E-mail Address'),
nga.field('created', 'date')
.label('Created')
.map(fromNow),
nga.field('modified', 'date')
.label('Modified')
.map(transformDate),
nga.field('active', 'boolean')
.label('Status'),
nga.field('createdBy')
.label('Created by'),
]);
下一段代码
$rootScope.$on('$stateChangeSuccess', function (event, newUrl, oldUrl, newState, oldState) {
console.log('event:' , event);
console.log('newUrl:' , newUrl);
console.log('oldUrl:' , oldUrl);
console.log('newState:' , newState);
console.log('oldState:' , oldState);
})
它在从仪表板转到用户时提供输出:
event: {name: "$stateChangeSuccess", targetScope: p, defaultPrevented: false, currentScope: p, preventDefault: ƒ}
newUrl: {url: "?{search:json}&{page:int}&sortField&sortDir", params: {…}, parent: "listLayout", views: {…}, name: "list"}
oldUrl: {entity: "users", search: {…}, page: 1, sortField: null, sortDir: null}
newState: {parent: "ng-admin", url: "/dashboard?sortField&sortDir", params: {…}, controller: "DashboardController", controllerAs: "dashboardController", …}
oldState: {sortField: null, sortDir: null}
并在刷新时
event: {name: "$stateChangeSuccess", targetScope: p, defaultPrevented: false, currentScope: p, preventDefault: ƒ}
newUrl: {parent: "ng-admin", url: "/dashboard?sortField&sortDir", params: {…}, controller: "DashboardController", controllerAs: "dashboardController", …}
oldUrl: {sortField: null, sortDir: null}
newState: {url: "?{search:json}&{page:int}&sortField&sortDir", params: {…}, parent: "listLayout", views: {…}, name: "list"}
oldState: {entity: "users", search: {…}, page: 1, sortField: null, sortDir: null}
任何想法表示赞赏。
问题是我在 header 控制器函数中有一个错误,该函数添加了转到仪表板的方法,并且每次 header 重新初始化时都会调用它。也许这会对某人有所帮助。
我一直卡在刷新页面的问题上。示例:基本应用程序打开并且 url 是 localhost:8000/dashboard
,然后我从菜单或其他任何地方转到用户选项卡并且 url 是 localhost:8000/users/list
。如果我在用户上刷新页面,那么它会再次进入仪表板重新加载整个页面。
后端正在正确处理它,当我创建一个自定义状态并且不指定 'ng-admin' 作为父级时,它停留在它只是进行刷新的位置,但是当我将父级添加到状态时,它会再次重新加载整个应用程序。
还启用了 html5mode。
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
实体添加为 ng-admin 文档指定:
app.config(['NgAdminConfigurationProvider', 'RestangularProvider', function(nga, RestangularProvider) {
var admin = nga.application('Admin') // application main title
.debug(false) // debug disabled
.baseApiUrl('/api/'); // main API endpoint
var users = nga.entity('users');
admin
.addEntity(users);
users.listView()
.title('Admin users')
.fields([
nga.field('name')
.label('Name')
.isDetailLink(true),
nga.field('email')
.label('E-mail Address'),
nga.field('created', 'date')
.label('Created')
.map(fromNow),
nga.field('modified', 'date')
.label('Modified')
.map(transformDate),
nga.field('active', 'boolean')
.label('Status'),
nga.field('createdBy')
.label('Created by'),
]);
下一段代码
$rootScope.$on('$stateChangeSuccess', function (event, newUrl, oldUrl, newState, oldState) {
console.log('event:' , event);
console.log('newUrl:' , newUrl);
console.log('oldUrl:' , oldUrl);
console.log('newState:' , newState);
console.log('oldState:' , oldState);
})
它在从仪表板转到用户时提供输出:
event: {name: "$stateChangeSuccess", targetScope: p, defaultPrevented: false, currentScope: p, preventDefault: ƒ}
newUrl: {url: "?{search:json}&{page:int}&sortField&sortDir", params: {…}, parent: "listLayout", views: {…}, name: "list"}
oldUrl: {entity: "users", search: {…}, page: 1, sortField: null, sortDir: null}
newState: {parent: "ng-admin", url: "/dashboard?sortField&sortDir", params: {…}, controller: "DashboardController", controllerAs: "dashboardController", …}
oldState: {sortField: null, sortDir: null}
并在刷新时
event: {name: "$stateChangeSuccess", targetScope: p, defaultPrevented: false, currentScope: p, preventDefault: ƒ}
newUrl: {parent: "ng-admin", url: "/dashboard?sortField&sortDir", params: {…}, controller: "DashboardController", controllerAs: "dashboardController", …}
oldUrl: {sortField: null, sortDir: null}
newState: {url: "?{search:json}&{page:int}&sortField&sortDir", params: {…}, parent: "listLayout", views: {…}, name: "list"}
oldState: {entity: "users", search: {…}, page: 1, sortField: null, sortDir: null}
任何想法表示赞赏。
问题是我在 header 控制器函数中有一个错误,该函数添加了转到仪表板的方法,并且每次 header 重新初始化时都会调用它。也许这会对某人有所帮助。