使用 webpack 更改路由时如何卸载 css?

How to unload css when changing route using webpack?

angular-ui-router changing route unloads the current state's css (using angular-css).

然而,当 css 使用 webpack 打包时,状态的 css 不会卸载。

有办法解决这个问题吗?

我们找到了解决方法,但我们更喜欢真正的修复。

我们结合了useable styles and two undocumented broadcasts in angular-css ($cssAdd and $cssRemove)

代码如下所示:

  $rootScope.$on('$cssAdd', function (event, stylesheets) {
    angular.forEach( stylesheets, function(stylesheet){
      if (stylesheet.use)
        stylesheet.use();
    });
  });
  $rootScope.$on('$cssRemove', function (event, stylesheets) {
    angular.forEach( stylesheets, function(stylesheet){
      if (stylesheet.unuse)
        stylesheet.unuse();
    });
  });