angular - router-outlet 在页面上占用额外空间(Angular 2)

标签 angular router markup

这是一个有趣的问题,直到现在我都忽略了它。 看起来 Angular2 呈现指令标签内的内容。但是,对于 router-outlet,它恰好就像一个 sibling 。

我的第一个问题是:为什么?只是出于兴趣。

我不会太担心它,但它现在实际上在我的应用程序中引起了问题。我有两个嵌套的导出,由于一些莫名其妙的原因, child 在页面上占据了 15px 的高度,无论我做什么,我都无法摆脱它。 (见截图) enter image description here

我描述的是真的还是我只是做错了什么? 另外,我现在不知道如何处理这个问题,到处搜索,没有找到任何东西。

感谢您的帮助。

更新 这是我的 less 文件:

@import "../../node_modules/bootstrap-less/bootstrap/bootstrap";
@import "../../node_modules/font-awesome/less/font-awesome";
@icon-font-path: "./bootstrap/fonts/";
@fa-font-path: "./font-awesome/fonts";
@import "rrm.less";

html, body {
  height: 100% !important;
}
body {
  padding-top: 80px;
}
.load-container {
  background: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
  .loaing {
    position: fixed;
    left: 50%;
    top: 35%;
    z-index: 1000;
    height: 31px;
    width: 31px;
  }
}
.top-navbar {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  background-color: #FFFFFF;
  height: 80px;
  &.floating {
    .box-shadow(0 1px 3px rgba(0,0,0,.25));
  }
  .navbar-brand {
    height: auto;
    img {
      height: 60px;
    }
  }
  .navbar-nav > li > a {
    font-size: 20px;
    padding-top: 15px;
    padding-bottom: 15px;
    line-height: 50px;
  }
}
.rrm-container {
  height:100%;
  display: table;
  width: 100%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  padding-left: 0px;
  padding-right: 0px;
  .rrm-wrapper {
    height: 100%;
    display: table-row;
    .left-menu {
      float: none;
      display: table-cell;
      .box-shadow(0 1px 3px rgba(0,0,0,.25));
      ul {
        li {
          border: none;
          background-color: transparent;
        }
      }
    }
    .content {
      float: none;
      display: table-cell;
    }
  }
}

这是 FF 计算的盒模型: enter image description here

enter image description here

最佳答案

为了回答您的第一个问题,即为什么将组件模板作为 <router-outlet> 的同级放置而不是在其中,有几个 github 线程可以阐明一些问题。

https://github.com/angular/angular/issues/8529#issuecomment-217718704 https://github.com/angular/angular/issues/4679

最相关:

The original reason for this behavior was to enable animation of elements between views during which time both source and destination components would need to be active

关于angular - router-outlet 在页面上占用额外空间(Angular 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36514439/

相关文章:

javascript - 如何为 Angular 2 中的特定路由实现 RouteReuseStrategy shouldDetach

angular - 在 Angular2 中,mailto 链接被识别为组件路由

javascript - VueJs (Quasar), vuex store access in router

vue.js - 将来自 URL 的参数与 Vue 路由器配置中的 props 对象结合起来

重定向后的 Angular 浏览器后退按钮

ruby-on-rails - Rails,带有嵌套 HTML 的标签,使用 FormBuilder 和 Devise,带有 Bootstrap 标记

angular - Laravel 5.4 中的 Access-Control-Allow-Origin header 响应不适用于 POST

angular - 如何无边距全屏

css - 如何覆盖 chrome 中的嵌入样式?

markup - 纺织品编号标题