在构建应用程序中进行路由时出现Angular 5问题

时间:2018-03-26 07:41:01

标签: angular

在我的角5的应用程序,当我尝试内置应用程序,我有一些问题,如果说我这是确定的网页浏览正常,但如果我重新加载详细信息页面好像不会加载的字体(我加载的所有字体从我assets文件夹,因为应用程序必须在没有在线依赖项的情况下工作) 如果我重新加载非详细信息页面它很好,为什么?

app.routing

  {
    path: 'ticketBundles',
    loadChildren: './ticket-bundles/shared/ticket-bundle.module#TicketBundleModule',
    data: { roles: ['role.admin', 'role.backoffice'] }
  },

ticketBundleRouting.module

import { NgModule } from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {TicketBundleListComponent} from '../ticket-bundle-list/ticket-bundle-list.component';
import {TicketBundleNewComponent} from '../ticket-bundle-new/ticket-bundle-new.component';
import {TicketBundleDetailComponent} from '../ticket-bundle-detail/ticket-bundle-detail.component';

const TicketBundleRoutes: Routes = [
  {
    path: '',
    component: TicketBundleListComponent
  },
  {
    path: 'new',
    component: TicketBundleNewComponent
  },
  {
    path: ':code',
    component: TicketBundleDetailComponent,
  },
  {
    path: ':code/copy',
    component: TicketBundleNewComponent
  }
];

@NgModule({
  imports: [
    RouterModule.forChild(TicketBundleRoutes)
  ],
  exports: [
    RouterModule
  ]
})

export class TicketBundleRoutingModule { }

并且在angular-cli.json

"styles": [
                "app-styles.css",
                "./assets/css/fonts.css",
                .....

2 个答案:

答案 0 :(得分:1)

尝试添加index.html基本路径:

<base href="/">

答案 1 :(得分:0)

更改

"styles": [... "./assets/css/fonts.css",

"styles": [... "/assets/css/fonts.css",

如果没有帮助,请尝试在scss文件中加载字体。

styles.scss:

@font-face { font-family: "your font name"; src: url("/assets/source-of-font"); }

$globally-available-font-variable: "your font name";

在任何组件的scss中:

@import './src/style.scss';

.somediv{
  font: $globally-available-font-variable
}