I'm new to Angular. I've the following folder/file tree:
-- app folder
-- root (
-- pages (pages-routing, pages-module, pages-component)
-- page1 (page1-routing, page1-component)
-- subcomponent (subcomponent-component)
My pages-routing is defined this way
const routes: Routes = [{
path: '',
component: PagesComponent,
children: [{
path: 'page1',
component: Page1Component,
}, {
path: 'subcomponent',
component: SubComponent,
}],
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class PagesRoutingModule { }
export const routedComponents = [
Page1Component,
SubComponent,
];
The Pages NgModule
@NgModule({
imports: [
ThemeModule,
PagesRoutingModule,
],
declarations: [
...routedComponents,
],
providers: [
SmartTableService,
],
})
The Page1 NgModule looks similiar:
@NgModule({
imports: [
ThemeModule,
PagesRoutingModule,
Ng2SmartTableModule,
],
declarations: [
...routedComponents,
],
providers: [
SmartTableService,
],
})
This works but my Question is ..I wonder if it is possible to remove the route for the subcomponent ..since the subcomponent doesnt need to have a route for real ? What i did so far is to try to remove from the pages-routing this
{
path: 'subcomponent',
component: SubComponent,
}
and
{
SubComponent,
}
and I added SubComponent reference in both Pages NgModule and Page1 NgModule Declarations sections but I get: No component factory found for SubComponent
So the real question. Is it mandatory to have a route for component ? Can a Component live Without a Route ?