【问题标题】:Angular2 router with param reload page change get CSS file directory带有参数重新加载页面更改的Angular2路由器获取CSS文件目录
【发布时间】:2017-02-22 03:21:57
【问题描述】:

通常如果我单击主页链接上的链接到详细链接,例如<a routerLink="/detail/{{record.TA001}}">,它工作得很好,css 文件也很好。

因为只有我刷新了这个详情页,比如localhost:3000/detail/0006 它得到了数据,但是获取 CSS 文件将目录更改为详细目录而不是根目录,无法获取 CSS 文件。我的详细组件在app/content 目录中。

我的index.html 和项目根目录中的 CSS 文件。 路由器:

const appRoutes: Routes = [
  {
    path: 'contact',
    component: Contactcomponent
  },
  {
    path: 'detail/:id',
    component: Detailcomponent
  },
  { path: '',
   component: Contentcomponent
  }

我的项目目录是这样的:

【问题讨论】:

标签: css angular reload router params


【解决方案1】:

我知道如何解决这个问题,只需将路由器指令 /detail/0005 更改为 /0005,它就可以正常工作。我认为如果路由器是root,所以你可以使用一级就好了。它不能使用二级方法,如果你的路由器不是root,它可以使用它。

【讨论】:

    【解决方案2】:

    如果您想使用相对路径而不是每次都计算绝对路径(使用 ../ ../../ 等),您应该在组件声明中使用 moduleID 属性,如 here. 所解释的那样

    【讨论】:

      【解决方案3】:

      在包含 css/stylesheet 之前检查是否在 index.html 中包含 base href="/"

      【讨论】:

        猜你喜欢
        • 2017-03-15
        • 2017-05-14
        • 1970-01-01
        • 1970-01-01
        • 2021-09-28
        • 2019-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多