简体   繁体   English

CSS覆盖单页面应用程序中的不同页面

[英]CSS overriding for different pages in Single page application

I am building SPA with angular.js , two pages, login and dashboard has different background, but since it's a single page application after login the background color doesn't change to the new color mentioned in dashboard.less file. 我正在使用angular.js构建SPA,两个页面,登录和仪表板具有不同的背景,但由于登录后它是单页应用程序,因此背景颜色不会更改为dashboard.less文件中提到的新颜色。 In this case I use !important , dashboard background get reflected even after logout. 在这种情况下,我使用!important ,仪表板背景即使在注销后也会反映出来。

I want specific page css only to be loaded on ui-routing. 我希望特定的页面css只能加载到ui-routing上。

Kindly suggest a fix for it. 请建议修复它。 I am using less with webpack. 我用webpack少用。 I know such issues will come for later pages too. 我知道这些问题也会在以后的页面中出现。 How can I avoid this problem. 我怎样才能避免这个问题。

I think we have a solution here https://github.com/manuelmazzuola/angular-ui-router-styles 我想我们有一个解决方案https://github.com/manuelmazzuola/angular-ui-router-styles

Add this framwork and use it like 添加这个框架并使用它

 .state('state1', {
    url: '/state1',
    controller: 'State1controller',
    template: '<div ui-view></div>',
    data: {
      css: [
        'styles/custom-state1.css',
        {
          name: 'layout',
          href: 'styles/state1-layout.css'
        }
      ]
    }
  })

well you could do something like this. 那么你可以做这样的事情。

<link data-ng-if="page.css" rel="stylesheet" type="text/css" data-ng-href="css/app/page/{{page.css}}/page.css" />

where when you do a ui-routing and load the controller. 当你进行ui路由并加载控制器时。

you would have 你将会拥有

$scope.page = {css: "loginpage"};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM