繁体   English   中英

静态HTML的Angular 2+路径

[英]Angular 2+ path to static html

在我的Angular 2+应用程序之一中,我要求显示静态html文件内容。 因此,我将该静态html(helper.html)放在assets文件夹中,可以通过以下方式访问它:

http://localhost:4200/assets/helper.html

但是,一旦我引入了路由模块,就会出现以下错误:

Error: Cannot match any routes. URL Segment: 'assets/static/helper.html' noMatchError

要使此路径正常工作,我需要在路由模块中做什么?

PS:以下是我的路由模块的摘要:

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full'},
  { path: 'home', component: HomeComponent }
]

@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule { }

此html必须与组件一起使用。 没有它是没有办法的。

为其添加一个组件文件并为其设置一个URL

static.component

import {Component} from '@angular/core'
@Component({
    templateUrl:'helper.html'
})
export class StaticComponent{
}

APP-routing.module.ts

import {StaticComponet} from '../assets/static.component.ts';
const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full'},
  { path: 'home', component: HomeComponent },
{path:'helper',component:StaticComponent}
]

@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule { }

暂无
暂无

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

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