[英]Angular - how to load a component without the root component?
我正在使用angular 8進行購物Web應用程序項目。
管理員有一個商店網址和cms(內容管理系統)。
我希望在導航到“ localhost:4200 / cms”時加載CMS模塊。
可以實施嗎? 以下是我的代碼。
//******* app.component.html *********/
<app-header></app-header>
<main role="main">
<router-outlet (message)="handleMessage($event)"></router-outlet>
</main>
<footer class="text-muted">
<app-footer></app-footer>
</footer>
//******* app-routing.module.ts *********/
const routes: Routes = [
{path: '', component:MainComponent, pathMatch:'full'},
{path: 'cart', component: CartComponent},
{path: 'shop/:product_category', component:ProductCategoryComponent},
{path: 'cms', loadChildren: ()=> import ('./cms/cms.module').then(mod=>mod.CmsModule)},
{path: '**', component:NotFoundComponent}
];
//******* cms-routing.module.ts *********/
const routes: Routes = [
{path: '', component:CmsComponent, children:[
{path: '', redirectTo: 'cms'},
{path: 'product-categories', component:ProductCategoriesComponent},
{path: 'product-categories/create', component: CreateProductCategoryComponent},
{path: 'product-categories/edit/:id', component: EditProductCateogryComponent},
{path: 'products', component: ProductsComponent},
{path: 'products/create', component: CreateProductComponent},
{path: 'orders', component: OrdersComponent},
]},
];
我認為您無法做到這一點,因為Angular需要應用程序根目錄,因此它知道在哪里呈現內容。
不知道命名路由器插座是否符合您的需求。
據我了解,在角度結構中,組件是角度應用程序的基本構建塊,因此在角度應用程序中始終存在一個或多個組件。
這意味着我們至少需要一個角度組件來渲染角度應用程序。 並且app.component是根組件,因此我們必須使用app.component(app-root)來呈現任何角度應用程序。
如果您的CMS是從角度不同的應用程序,那么你可以通過使用角度RedirectGuard管理此: 參考,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.