说我有这个:
<router-outlet></router-outlet>
在路由器中:
const routes: Routes = [
{ path: 'about', component: AboutComponent},
{ path: '404', component: PageNotFoundComponent },
{ path: '', component: EmptyComponent, pathMatch: 'full' },
{ path: '**', redirectTo: '/404' }
];
组件:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home', // do we want/need this? Or should I remove?
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
如果我转到/关于它,它应该将about页面呈现给<router-outlet>
元素,所以我认为我不需要选择器字段吗?
答案 0 :(得分:3)
如果您愿意,可以删除选择器。
但这意味着您无法在任何其他模板中使用<app-home></app-home>
。