gpt4 book ai didi

javascript - 如何防止刷新页面后重新加载整个 ng-admin

转载 作者:行者123 更新时间:2023-11-28 04:03:07 25 4
gpt4 key购买 nike

我一直遇到刷新页面的问题。示例:基础应用程序打开,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 Controller 功能中出现错误,该功能添加了前往仪表板的方法,并且每次 header 重新初始化时都会调用它。也许这会对某人有所帮助。

关于javascript - 如何防止刷新页面后重新加载整个 ng-admin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46927475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com