新建一个StaticRouteModule:
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CmsPageGuard } from '@spartacus/storefront';
import { StaticRouteComponent } from './static.route.component';
const staticRoutes: Routes = [{
path: 'static-page',
component: StaticRouteComponent,
canActivate: [CmsPageGuard]
}];
@NgModule({
declarations: [StaticRouteComponent],
imports: [
CommonModule,
RouterModule.forChild(staticRoutes)
]
})
export class StaticRouteModule { }
新建StaticRouteComponent:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-static.route',
templateUrl: './static.route.component.html'
})
export class StaticRouteComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
template只有一行代码:
<p>static.route works!</p>
在app.module.ts里导入新建的module:
最后运行结果:http://localhost:4202/electronics-spa/en/USD/static-page
更多Jerry的原创文章,尽在:"汪子熙":
网友评论