gpt4 book ai didi

angularjs - 如何在整个页面上显示 ui-router 状态?

转载 作者:行者123 更新时间:2023-12-04 22:58:34 24 4
gpt4 key购买 nike

我正在使用 ui-router 进行状态处理。这工作正常,但现在我必须创建页面 404 并希望将其显示在整个页面上,而不是像其他页面一样在页面内显示。

app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider) {

$locationProvider.hashPrefix('!').html5Mode({
enabled: true,
requireBase: false
});

$stateProvider
.state('stateIndex', {
url: '/',
templateUrl: '/templates/list.html',
controller: 'dashListController'
})
.state('stateList', {
url: '/list',
templateUrl: '/templates/list.html',
controller: 'dashListController'
}).state('stateDashboard', {
url: '/dashboard/:id',
templateUrl: '/templates/dashboard.html',
controller: 'dashboardController'
})
.state('stateWidgetsList', {
url: '/widgetsList',
templateUrl: '/templates/widgetsList.html',
controller: 'widgetsListController'
})
.state('404', {
url: '/404',
templateUrl: '/templates/404.html'
});
}]);

在我的 index.html 上我有
<div ui-view></div>

我在其中显示所有页面,除此之外我有 Logo 、菜单等。我想在显示 404 页面时隐藏它们。

我该怎么做?

最佳答案

我个人会重新设计 index.html,并将外部模板( Logo 、菜单等)带入它自己的模板和状态。然后,您可以在 ui-router 层次结构中将子状态置于其下方。例如:

$stateProvider
.state('app', {
abstract: true,
url: '',
templateUrl: '/templates/appcontainer.html'
})
.state('app.stateIndex', {
url: '/',
templateUrl: '/templates/list.html',
controller: 'dashListController'
})
.state('404', {
url: '/404',
templateUrl: '/templates/404.html'
});

然后,您只需将您的 Logo /菜单等放入 appcontainer.html ,然后只有一个 <div ui-view></div>在您的 index.html 中。另外,如果您这样做,请不要忘记添加 child ui-view里面 appcontainer.html .

关于angularjs - 如何在整个页面上显示 ui-router 状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34045899/

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